The photo upload limit for user profiles is raised from 24 to 100. The bug about Filesize not saving to the database for Photos and CommentPhotos (storing zeroes in the DB) has been fixed. Run the `nonshy backfill filesizes` to populate your existing database.pull/12/head
parent
fd0ff31d3e
commit
8e4bb85934
7 changed files with 91 additions and 1 deletions
@ -0,0 +1,64 @@ |
||||
package backfill |
||||
|
||||
import ( |
||||
"os" |
||||
|
||||
"code.nonshy.com/nonshy/website/pkg/log" |
||||
"code.nonshy.com/nonshy/website/pkg/models" |
||||
"code.nonshy.com/nonshy/website/pkg/photo" |
||||
) |
||||
|
||||
// BackfillFilesizes finds Photos and CommentPhotos which have a zero Filesize and recomputes them.
|
||||
func BackfillFilesizes() error { |
||||
// Find Photos with a filesize of zero.
|
||||
var ( |
||||
photos []*models.Photo |
||||
commentPhotos []*models.CommentPhoto |
||||
) |
||||
|
||||
// Query for photos w/ zero filesize.
|
||||
result := models.DB.Model(&models.Photo{}).Where("filesize = 0").Find(&photos) |
||||
if result.Error != nil { |
||||
return result.Error |
||||
} |
||||
|
||||
// And CommentPhotos too.
|
||||
result = models.DB.Model(&models.CommentPhoto{}).Where("filesize = 0").Find(&commentPhotos) |
||||
if result.Error != nil { |
||||
return result.Error |
||||
} |
||||
|
||||
// Do the Photos.
|
||||
for i, row := range photos { |
||||
// Set the filesize from disk.
|
||||
if stat, err := os.Stat(photo.DiskPath(row.Filename)); err == nil { |
||||
row.Filesize = stat.Size() |
||||
} |
||||
|
||||
log.Info("[%d of %d] Update photo %d: %s filesize=%d", |
||||
i+1, len(photos), row.ID, row.Filename, row.Filesize, |
||||
) |
||||
|
||||
if err := row.Save(); err != nil { |
||||
return err |
||||
} |
||||
} |
||||
|
||||
// And same for the CommentPhotos.
|
||||
for i, row := range commentPhotos { |
||||
// Set the filesize from disk.
|
||||
if stat, err := os.Stat(photo.DiskPath(row.Filename)); err == nil { |
||||
row.Filesize = stat.Size() |
||||
} |
||||
|
||||
log.Info("[%d of %d] Update comment_photo %d: %s filesize=%d", |
||||
i+1, len(photos), row.ID, row.Filename, row.Filesize, |
||||
) |
||||
|
||||
if err := row.Save(); err != nil { |
||||
return err |
||||
} |
||||
} |
||||
|
||||
return nil |
||||
} |
@ -0,0 +1 @@ |
||||
package models |
Loading…
Reference in new issue