Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add support for storing albumEntries

Neeraj Guptac6836f6d884f
diff --git a/pkg/model/constants.go b/pkg/model/constants.go
index 65db2b4501..2a9f4cafa1 100644
--- a/pkg/model/constants.go
+++ b/pkg/model/constants.go
@@ -3,9 +3,10 @@ package model
type PhotosStore string
const (
- KVConfig PhotosStore = "kvConfig"
- RemoteAlbums PhotosStore = "remoteAlbums"
- RemoteFiles PhotosStore = "remoteFiles"
+ KVConfig PhotosStore = "kvConfig"
+ RemoteAlbums PhotosStore = "remoteAlbums"
+ RemoteFiles PhotosStore = "remoteFiles"
+ RemoteAlbumEntries PhotosStore = "remoteAlbumEntries"
)
const (
diff --git a/pkg/model/remote.go b/pkg/model/remote.go
index 812fe5475f..e3dd4e1ee1 100644
--- a/pkg/model/remote.go
+++ b/pkg/model/remote.go
@@ -30,3 +30,10 @@ type RemoteAlbum struct {
SharedMeta map[string]interface{} `json:"sharedMeta"`
LastUpdatedAt int64 `json:"lastUpdatedAt"`
}
+
+type AlbumFileEntry struct {
+ FileID int64 `json:"fileID"`
+ AlbumID int64 `json:"albumID"`
+ IsDeleted bool `json:"isDeleted"`
+ SyncedLocally bool `json:"localSync"`
+}
diff --git a/pkg/remote_sync.go b/pkg/remote_sync.go
index 78db914508..a6d6cd4813 100644
--- a/pkg/remote_sync.go
+++ b/pkg/remote_sync.go
@@ -58,16 +58,23 @@ func (c *ClICtrl) fetchRemoteFiles(ctx context.Context) error {
log.Printf("Skipping album %s as it is deleted", album.AlbumName)
continue
}
+
lastSyncTime, lastSyncTimeErr := c.GetInt64ConfigValue(ctx, fmt.Sprintf(model.CollectionsFileSyncKeyFmt, album.ID))
if lastSyncTimeErr != nil {
return lastSyncTimeErr
}
+
isFirstSync := lastSyncTime == 0
- for {
+ for {
if lastSyncTime == album.LastUpdatedAt {
break
}
+ if isFirstSync {
+ log.Printf("First sync for album %s\n", album.AlbumName)
+ } else {
+ log.Printf("Syncing album %s\n from %s", album.AlbumName, time.UnixMicro(lastSyncTime))
+ }
if !isFirstSync {
t := time.UnixMicro(lastSyncTime)
log.Printf("Fetching files for album %s from %v\n", album.AlbumName, t)
@@ -85,12 +92,22 @@ func (c *ClICtrl) fetchRemoteFiles(ctx context.Context) error {
// on first sync, no need to sync delete markers
continue
}
+ albumEntry := model.AlbumFileEntry{AlbumID: album.ID, FileID: file.ID, IsDeleted: file.IsDeleted, SyncedLocally: false}
+ albumEntryJson := encoding.MustMarshalJSON(albumEntry)
+ putErr := c.PutValue(ctx, model.RemoteAlbumEntries, []byte(fmt.Sprintf("%d:%d", album.ID, file.ID)), albumEntryJson)
+ if putErr != nil {
+ return putErr
+ }
+ if file.IsDeleted {
+ continue
+ }
photoFile, err := mapper.MapApiFileToPhotoFile(ctx, album, file, c.KeyHolder)
if err != nil {
return err
}
fileJson := encoding.MustMarshalJSON(photoFile)
- putErr := c.PutValue(ctx, model.RemoteFiles, []byte(strconv.FormatInt(file.ID, 10)), fileJson)
+ // todo: use batch put
+ putErr = c.PutValue(ctx, model.RemoteFiles, []byte(strconv.FormatInt(file.ID, 10)), fileJson)
if putErr != nil {
return putErr
}
@@ -98,7 +115,8 @@ func (c *ClICtrl) fetchRemoteFiles(ctx context.Context) error {
if !hasMore {
maxUpdated = album.LastUpdatedAt
}
- if maxUpdated > lastSyncTime || !hasMore {
+ if (maxUpdated > lastSyncTime) || !hasMore {
+ log.Printf("Updating last sync time for album %s to %s\n", album.AlbumName, time.UnixMicro(maxUpdated))
err = c.PutConfigValue(ctx, fmt.Sprintf(model.CollectionsFileSyncKeyFmt, album.ID), []byte(strconv.FormatInt(maxUpdated, 10)))
if err != nil {
return fmt.Errorf("failed to update last sync time: %s", err)
diff --git a/pkg/sync.go b/pkg/sync.go
index d253be2aee..d4a60f8102 100644
--- a/pkg/sync.go
+++ b/pkg/sync.go
@@ -78,7 +78,7 @@ func createDataBuckets(db *bolt.DB, account model.Account) error {
if err != nil {
return fmt.Errorf("create bucket: %s", err)
}
- for _, subBucket := range []model.PhotosStore{model.KVConfig, model.RemoteAlbums, model.RemoteFiles} {
+ for _, subBucket := range []model.PhotosStore{model.KVConfig, model.RemoteAlbums, model.RemoteFiles, model.RemoteAlbumEntries} {
_, err := dataBucket.CreateBucketIfNotExists([]byte(subBucket))
if err != nil {
return err