Skip to content

Commit

Permalink
Backend: Pre-cache tags and albums on vault unlock
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinSRG committed Sep 23, 2023
1 parent 8d78ac2 commit ae7c1f6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions backend/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func (sm *SessionManager) CreateSession(user string, key []byte, root bool, writ

sm.lock.Lock()

isFirstSession := len(sm.sessions) == 0

newSession := ActiveSession{
id: sessionId,
user: user,
Expand All @@ -77,6 +79,12 @@ func (sm *SessionManager) CreateSession(user string, key []byte, root bool, writ
LogError(err)
}

if isFirstSession {
// Pre-cache tags and albums
go sm.vault.tags.PreCacheTags(key)
go sm.vault.albums.PreCacheAlbums(key)
}

return sessionId
}

Expand Down
18 changes: 18 additions & 0 deletions backend/vault_album_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,21 @@ func (am *VaultAlbumsManager) OnMediaThumbnailUpdate(media_id uint64, key []byte

return nil
}

// Reads the albums and pre-caches them on vault unlock
// key - Vault decryption key
func (am *VaultAlbumsManager) PreCacheAlbums(key []byte) {
data, err := am.ReadAlbums(key)

if err != nil {
LogError(err)
return
}

// Pre-cache thumbnails
for album_id := range data.Albums {
am.thumbnail_cache.GetAlbumThumbnail(album_id, key)
}

LogDebug("Pre-cached albums")
}
12 changes: 12 additions & 0 deletions backend/vault_tag_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,15 @@ func (tm *VaultTagManager) RandomTaggedMedia(tag_name string, key []byte, seed i

return values, tag_id, nil
}

// Reads the tags and pre-caches them on vault unlock
// key - Vault decryption key
func (tm *VaultTagManager) PreCacheTags(key []byte) {
_, err := tm.ReadList(key)

if err != nil {
LogError(err)
}

LogDebug("Pre-cached tags")
}

0 comments on commit ae7c1f6

Please sign in to comment.