mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 19:39:19 +00:00
That's why I created a new column storing a MD5 hash of the path and made it unique. The MD5 hash has only 32 characters and can be generated natively in MySQL and MariaDB. It helps us to avoid maximum key length and in the same time enforce unique photo and album paths. - Added path_hash column to photo and album tables - Added down migration file for 005_utf8_migration (just for consistency) - Added PathHash field to Album and Photo struct - album_scanner.go and photo_scanner.goo perform checks by MD5 hash now
49 lines
884 B
Go
49 lines
884 B
Go
package models
|
|
|
|
import (
|
|
"database/sql"
|
|
)
|
|
|
|
type Album struct {
|
|
AlbumID int
|
|
Title string
|
|
ParentAlbum *int
|
|
OwnerID int
|
|
Path string
|
|
PathHash string
|
|
}
|
|
|
|
func (a *Album) ID() int {
|
|
return a.AlbumID
|
|
}
|
|
|
|
func (a *Album) FilePath() string {
|
|
return a.Path
|
|
}
|
|
|
|
func NewAlbumFromRow(row *sql.Row) (*Album, error) {
|
|
album := Album{}
|
|
|
|
if err := row.Scan(&album.AlbumID, &album.Title, &album.ParentAlbum, &album.OwnerID, &album.Path, &album.PathHash); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &album, nil
|
|
}
|
|
|
|
func NewAlbumsFromRows(rows *sql.Rows) ([]*Album, error) {
|
|
albums := make([]*Album, 0)
|
|
|
|
for rows.Next() {
|
|
var album Album
|
|
if err := rows.Scan(&album.AlbumID, &album.Title, &album.ParentAlbum, &album.OwnerID, &album.Path, &album.PathHash); err != nil {
|
|
return nil, err
|
|
}
|
|
albums = append(albums, &album)
|
|
}
|
|
|
|
rows.Close()
|
|
|
|
return albums, nil
|
|
}
|