From fc515aa375fec6bd2a72395482d45275ffb434f9 Mon Sep 17 00:00:00 2001 From: viktorstrate Date: Tue, 19 Jan 2021 17:31:37 +0100 Subject: [PATCH] Cleanup gorm model attributes + add indexes --- api/graphql/models/album.go | 2 +- api/graphql/models/media.go | 22 +++++++++++----------- api/graphql/models/share_token.go | 12 ++++++------ api/graphql/models/user.go | 6 +++--- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/api/graphql/models/album.go b/api/graphql/models/album.go index 4f290573..5f7e666a 100644 --- a/api/graphql/models/album.go +++ b/api/graphql/models/album.go @@ -10,7 +10,7 @@ import ( type Album struct { Model Title string `gorm:"not null"` - ParentAlbumID *int + ParentAlbumID *int `gorm:"index"` ParentAlbum *Album `gorm:"constraint:OnDelete:SET NULL;"` // OwnerID int `gorm:"not null"` // Owner User diff --git a/api/graphql/models/media.go b/api/graphql/models/media.go index f911237a..9e7ce228 100644 --- a/api/graphql/models/media.go +++ b/api/graphql/models/media.go @@ -11,22 +11,22 @@ import ( type Media struct { Model - Title string `gorm:"not null"` - Path string `gorm:"not null"` - PathHash string `gorm:"not null"` - AlbumID int `gorm:"not null"` - Album Album `gorm:"constraint:OnDelete:CASCADE;"` - ExifID *int + Title string `gorm:"not null"` + Path string `gorm:"not null"` + PathHash string `gorm:"not null;unique"` + AlbumID int `gorm:"not null;index"` + Album Album `gorm:"constraint:OnDelete:CASCADE;"` + ExifID *int `gorm:"index"` Exif *MediaEXIF `gorm:"constraint:OnDelete:SET NULL;"` MediaURL []MediaURL `gorm:"constraint:OnDelete:CASCADE;"` DateShot time.Time `gorm:"not null"` DateImported time.Time `gorm:"not null"` // Favorite bool `gorm:"not null, default:false"` - Type MediaType `gorm:"not null"` - VideoMetadataID *int + Type MediaType `gorm:"not null;index"` + VideoMetadataID *int `gorm:"index"` VideoMetadata *VideoMetadata `gorm:"constraint:OnDelete:SET NULL;"` SideCarPath *string - SideCarHash *string + SideCarHash *string `gorm:"unique"` // Only used internally CounterpartPath *string `gorm:-` @@ -72,12 +72,12 @@ const ( type MediaURL struct { Model - MediaID int `gorm:"not null"` + MediaID int `gorm:"not null;index"` Media Media `gorm:"constraint:OnDelete:CASCADE;"` MediaName string `gorm:"not null"` Width int `gorm:"not null"` Height int `gorm:"not null"` - Purpose MediaPurpose `gorm:"not null"` + Purpose MediaPurpose `gorm:"not null;index"` ContentType string `gorm:"not null"` FileSize int64 `gorm:"not null"` } diff --git a/api/graphql/models/share_token.go b/api/graphql/models/share_token.go index abb4ec11..91e4fdbd 100644 --- a/api/graphql/models/share_token.go +++ b/api/graphql/models/share_token.go @@ -6,14 +6,14 @@ import ( type ShareToken struct { Model - Value string `gorm:"not null"` - OwnerID int `gorm:"not null"` - Owner User `gorm:"constraint:OnDelete:CASCADE;"` - Expire *time.Time + Value string `gorm:"not null"` + OwnerID int `gorm:"not null;index"` + Owner User `gorm:"constraint:OnDelete:CASCADE;"` + Expire *time.Time `gorm:"index"` Password *string - AlbumID *int + AlbumID *int `gorm:"index"` Album *Album `gorm:"constraint:OnDelete:CASCADE;"` - MediaID *int + MediaID *int `gorm:"index"` Media *Media `gorm:"constraint:OnDelete:CASCADE;"` } diff --git a/api/graphql/models/user.go b/api/graphql/models/user.go index 2d4505d8..67adfe19 100644 --- a/api/graphql/models/user.go +++ b/api/graphql/models/user.go @@ -14,7 +14,7 @@ import ( type User struct { Model - Username string `gorm:"unique,size:128"` + Username string `gorm:"unique;size:128"` Password *string `gorm:"size:256` // RootPath string `gorm:"size:512` Albums []Album `gorm:"many2many:user_albums"` @@ -30,10 +30,10 @@ type UserMediaData struct { type AccessToken struct { Model - UserID int `gorm:"not null"` + UserID int `gorm:"not null;index"` User User `gorm:"constraint:OnDelete:CASCADE;"` Value string `gorm:"not null, size:24` - Expire time.Time `gorm:"not null"` + Expire time.Time `gorm:"not null;index"` } var ErrorInvalidUserCredentials = errors.New("invalid credentials")