Skip to content

Commit

Permalink
Search: Change time_format to RFC3339 and add "edited" filter #4300
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Mayer <michael@photoprism.app>
  • Loading branch information
lastzero committed May 27, 2024
1 parent b49e66e commit 7430adb
Show file tree
Hide file tree
Showing 53 changed files with 751 additions and 293 deletions.
2 changes: 1 addition & 1 deletion internal/api/share_preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func SharePreview(router *gin.RouterGroup) {

previewFilename := filepath.Join(thumbPath, shared+fs.ExtJPEG)

expires := entity.TimeStamp().Add(-1 * time.Hour)
expires := entity.Now().Add(-1 * time.Hour)

if info, err := os.Stat(previewFilename); err != nil {
log.Debugf("share: creating new preview for %s", clean.Log(shared))
Expand Down
20 changes: 10 additions & 10 deletions internal/entity/album.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func AddPhotoToUserAlbums(photoUid string, albums []string, userUid string) (err
}

// Refresh updated timestamp.
err = UpdateAlbum(albumUid, Map{"updated_at": TimePointer()})
err = UpdateAlbum(albumUid, Map{"updated_at": TimeStamp()})
}
}

Expand All @@ -152,7 +152,7 @@ func NewAlbum(albumTitle, albumType string) *Album {

// NewUserAlbum creates a new album owned by a user.
func NewUserAlbum(albumTitle, albumType, userUid string) *Album {
now := TimeStamp()
now := Now()

// Set default type.
if albumType == "" {
Expand Down Expand Up @@ -182,7 +182,7 @@ func NewFolderAlbum(albumTitle, albumPath, albumFilter string) *Album {
return nil
}

now := TimeStamp()
now := Now()

result := &Album{
AlbumOrder: sortby.Added,
Expand All @@ -205,7 +205,7 @@ func NewMomentsAlbum(albumTitle, albumSlug, albumFilter string) *Album {
return nil
}

now := TimeStamp()
now := Now()

result := &Album{
AlbumOrder: sortby.Oldest,
Expand All @@ -230,7 +230,7 @@ func NewStateAlbum(albumTitle, albumSlug, albumFilter string) *Album {
return nil
}

now := TimeStamp()
now := Now()

result := &Album{
AlbumOrder: sortby.Newest,
Expand Down Expand Up @@ -261,7 +261,7 @@ func NewMonthAlbum(albumTitle, albumSlug string, year, month int) *Album {
Public: true,
}

now := TimeStamp()
now := Now()

result := &Album{
AlbumOrder: sortby.Oldest,
Expand Down Expand Up @@ -392,7 +392,7 @@ func FindAlbum(find Album) *Album {

// Filter by creator if the album has not been published yet.
if find.CreatedBy != "" {
stmt = stmt.Where("published_at > ? OR created_by = ?", TimeStamp(), find.CreatedBy)
stmt = stmt.Where("published_at > ? OR created_by = ?", Now(), find.CreatedBy)
}

// Find first matching record.
Expand Down Expand Up @@ -710,7 +710,7 @@ func (m *Album) Delete() error {
return nil
}

now := TimeStamp()
now := Now()

if err := UnscopedDb().Model(m).UpdateColumns(Map{"updated_at": now, "deleted_at": now}).Error; err != nil {
return err
Expand Down Expand Up @@ -817,7 +817,7 @@ func (m *Album) AddPhotos(photos PhotosInterface) (added PhotoAlbums) {
}

// Refresh updated timestamp.
if err := UpdateAlbum(m.AlbumUID, Map{"updated_at": TimePointer()}); err != nil {
if err := UpdateAlbum(m.AlbumUID, Map{"updated_at": TimeStamp()}); err != nil {
log.Errorf("album: %s (update %s)", err.Error(), m)
}

Expand Down Expand Up @@ -845,7 +845,7 @@ func (m *Album) RemovePhotos(UIDs []string) (removed PhotoAlbums) {
}

// Refresh updated timestamp.
if err := UpdateAlbum(m.AlbumUID, Map{"updated_at": TimePointer()}); err != nil {
if err := UpdateAlbum(m.AlbumUID, Map{"updated_at": TimeStamp()}); err != nil {
log.Errorf("album: %s (update %s)", err.Error(), m)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/entity/auth_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (m *Session) Regenerate() *Session {
m.RefID = rnd.RefID(SessionPrefix)

// Get current time.
now := TimeStamp()
now := Now()

// Set timestamps to now.
m.CreatedAt = now
Expand Down Expand Up @@ -961,7 +961,7 @@ func (m *Session) SetClientIP(ip string) {

if m.LoginIP == "" {
m.LoginIP = ip
m.LoginAt = TimeStamp()
m.LoginAt = Now()
}

return
Expand Down
2 changes: 1 addition & 1 deletion internal/entity/auth_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func (m *User) UpdateLoginTime() *time.Time {
return nil
}

timeStamp := TimePointer()
timeStamp := TimeStamp()

if err := Db().Model(m).UpdateColumn("LoginAt", timeStamp).Error; err != nil {
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/entity/auth_user_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ var UserFixtures = UserMap{
CanLogin: false,
WebDAV: true,
CanInvite: false,
DeletedAt: TimePointer(),
DeletedAt: TimeStamp(),
UserSettings: &UserSettings{
UITheme: "",
MapsStyle: "",
Expand Down
8 changes: 4 additions & 4 deletions internal/entity/auth_user_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func NewUserShare(userUID, shareUid string, perm uint, expires *time.Time) *User
ShareUID: shareUid,
Perm: perm,
RefID: rnd.RefID(SharePrefix),
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
ExpiresAt: expires,
}

Expand Down Expand Up @@ -119,7 +119,7 @@ func FindUserShares(userUid string) UserShares {
}

// Find matching record.
if err := UnscopedDb().Find(&found, "user_uid = ? AND (expires_at IS NULL OR expires_at > ?)", userUid, TimeStamp()).Error; err != nil {
if err := UnscopedDb().Find(&found, "user_uid = ? AND (expires_at IS NULL OR expires_at > ?)", userUid, Now()).Error; err != nil {
event.AuditWarn([]string{"user %s", "find shares", "%s"}, clean.Log(userUid), err)
return nil
}
Expand Down Expand Up @@ -156,7 +156,7 @@ func (m *UserShare) UpdateLink(link Link) error {
m.LinkUID = link.LinkUID
m.Comment = link.Comment
m.Perm = link.Perm
m.UpdatedAt = TimeStamp()
m.UpdatedAt = Now()
m.ExpiresAt = link.ExpiresAt()

values := Map{
Expand Down
4 changes: 2 additions & 2 deletions internal/entity/auth_user_share_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ var UserShareFixtures = UserShareMap{
Comment: "The quick brown fox jumps over the lazy dog.",
Perm: PermShare,
RefID: rnd.RefID(SharePrefix),
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
},
}

Expand Down
2 changes: 1 addition & 1 deletion internal/entity/auth_user_share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestUserShares_Contains(t *testing.T) {
}

func TestNewUserShare(t *testing.T) {
expires := TimeStamp().Add(time.Hour * 48)
expires := Now().Add(time.Hour * 48)
m := NewUserShare(Admin.GetUID(), AlbumFixtures.Get("berlin-2019").AlbumUID, PermReact, &expires)

assert.True(t, m.HasID())
Expand Down
4 changes: 2 additions & 2 deletions internal/entity/camera_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ var CameraFixtures = CameraMap{
CameraType: "",
CameraDescription: "",
CameraNotes: "",
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
DeletedAt: nil,
},
}
Expand Down
40 changes: 20 additions & 20 deletions internal/entity/cell_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ var CellFixtures = CellMap{
CellName: "Adosada Platform",
CellCategory: "botanical garden",
Place: PlaceFixtures.Pointer("mexico"),
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
},
"caravan park": {
ID: s2.TokenPrefix + "1ef75a71a36c",
Expand All @@ -41,76 +41,76 @@ var CellFixtures = CellMap{
PlaceCity: "Mandeni",
PlaceState: "KwaZulu-Natal",
PlaceCountry: "za",
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
},
CellName: "Lobotes Caravan Park",
CellCategory: "camping",
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
},
"zinkwazi": {
ID: s2.TokenPrefix + "1ef744d1e28c",
PlaceID: PlaceFixtures.Get("zinkwazi").ID,
Place: PlaceFixtures.Pointer("zinkwazi"),
CellName: "Zinkwazi Beach",
CellCategory: "beach",
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
},
"hassloch": {
ID: s2.TokenPrefix + "1ef744d1e280",
PlaceID: PlaceFixtures.Get("holidaypark").ID,
Place: PlaceFixtures.Pointer("holidaypark"),
CellName: "Holiday Park",
CellCategory: "park",
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
},
"emptyNameLongCity": {
ID: s2.TokenPrefix + "1ef744d1e281",
PlaceID: PlaceFixtures.Get("emptyNameLongCity").ID,
Place: PlaceFixtures.Pointer("emptyNameLongCity"),
CellName: "",
CellCategory: "botanical garden",
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
},
"emptyNameShortCity": {
ID: s2.TokenPrefix + "1ef744d1e282",
PlaceID: PlaceFixtures.Get("emptyNameShortCity").ID,
Place: PlaceFixtures.Pointer("emptyNameShortCity"),
CellName: "",
CellCategory: "botanical garden",
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
},
"veryLongLocName": {
ID: s2.TokenPrefix + "1ef744d1e283",
PlaceID: PlaceFixtures.Get("veryLongLocName").ID,
Place: PlaceFixtures.Pointer("veryLongLocName"),
CellName: "longlonglonglonglonglonglonglonglonglonglonglonglongName",
CellCategory: "cape",
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
},
"mediumLongLocName": {
ID: s2.TokenPrefix + "1ef744d1e283",
PlaceID: PlaceFixtures.Get("mediumLongLocName").ID,
Place: PlaceFixtures.Pointer("mediumLongLocName"),
CellName: "longlonglonglonglonglongName",
CellCategory: "botanical garden",
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
},
"Neckarbrücke": {
ID: s2.TokenPrefix + "1ef744d1e284",
PlaceID: PlaceFixtures.Get("Germany").ID,
Place: PlaceFixtures.Pointer("Germany"),
CellName: "Neckarbrücke",
CellCategory: "",
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
},
}

Expand Down
2 changes: 1 addition & 1 deletion internal/entity/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func FirstOrCreateDetails(m *Details) *Details {
return m
} else if err := Db().Where("photo_id = ?", m.PhotoID).First(&result).Error; err == nil {
if m.CreatedAt.IsZero() {
m.CreatedAt = TimeStamp()
m.CreatedAt = Now()
}

return &result
Expand Down
12 changes: 6 additions & 6 deletions internal/entity/details_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ var DetailsFixtures = DetailsMap{
Artist: "Hans",
Copyright: "copy",
License: "MIT",
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
KeywordsSrc: "meta",
NotesSrc: "manual",
SubjectSrc: "meta",
Expand All @@ -48,8 +48,8 @@ var DetailsFixtures = DetailsMap{
Artist: "Hans",
Copyright: "copy",
License: "MIT",
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
KeywordsSrc: "",
NotesSrc: "",
SubjectSrc: "meta",
Expand All @@ -65,8 +65,8 @@ var DetailsFixtures = DetailsMap{
Artist: "Jens Mander",
Copyright: "Copyright 2020",
License: report.NotAssigned,
CreatedAt: TimeStamp(),
UpdatedAt: TimeStamp(),
CreatedAt: Now(),
UpdatedAt: Now(),
KeywordsSrc: "meta",
NotesSrc: "manual",
SubjectSrc: "meta",
Expand Down
6 changes: 3 additions & 3 deletions internal/entity/entity_save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestSave(t *testing.T) {
t.Run("HasCreatedUpdatedAt", func(t *testing.T) {
id := 99999 + rand.IntN(10000)
m := Photo{ID: uint(id), PhotoUID: rnd.GenerateUID(PhotoUID), UpdatedAt: TimeStamp(), CreatedAt: TimeStamp()}
m := Photo{ID: uint(id), PhotoUID: rnd.GenerateUID(PhotoUID), UpdatedAt: Now(), CreatedAt: Now()}

if err := m.Save(); err != nil {
t.Fatal(err)
Expand All @@ -23,7 +23,7 @@ func TestSave(t *testing.T) {
})
t.Run("HasCreatedAt", func(t *testing.T) {
id := 99999 + rand.IntN(10000)
m := Photo{ID: uint(id), PhotoUID: rnd.GenerateUID(PhotoUID), CreatedAt: TimeStamp()}
m := Photo{ID: uint(id), PhotoUID: rnd.GenerateUID(PhotoUID), CreatedAt: Now()}

if err := m.Save(); err != nil {
t.Fatal(err)
Expand All @@ -34,7 +34,7 @@ func TestSave(t *testing.T) {
})
t.Run("NoCreatedAt", func(t *testing.T) {
id := 99999 + rand.IntN(10000)
m := Photo{ID: uint(id), PhotoUID: rnd.GenerateUID(PhotoUID), CreatedAt: TimeStamp()}
m := Photo{ID: uint(id), PhotoUID: rnd.GenerateUID(PhotoUID), CreatedAt: Now()}

if err := m.Save(); err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 7430adb

Please sign in to comment.