Skip to content

armgit / ente

Public Imported from GitHub
0

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

Retry file count initialization after stale cleanup

Neeraj Gupta9f2f1b40007f
diff --git a/server/pkg/controller/usage_file_count_init.go b/server/pkg/controller/usage_file_count_init.go
index e325de5c97..828a0a64f7 100644
--- a/server/pkg/controller/usage_file_count_init.go
+++ b/server/pkg/controller/usage_file_count_init.go
@@ -91,8 +91,10 @@ func (c *FileCountInitializer) initializeUser(userID int64) bool {
log.WithError(cleanupErr).WithField("user_id", userID).Error("Failed to find stale deleted file memberships")
}
cleaned := false
+ retryNow := len(fileIDs) < repo.StaleDeletedFileLimit
for _, fileID := range fileIDs {
if cleanupErr := c.TrashRepo.CleanUpDeletedFilesFromCollection(ctx, []int64{fileID}, userID); cleanupErr != nil {
+ retryNow = false
log.WithError(cleanupErr).WithFields(log.Fields{
"user_id": userID,
"file_id": fileID,
@@ -101,8 +103,15 @@ func (c *FileCountInitializer) initializeUser(userID int64) bool {
cleaned = true
}
}
+ if !cleaned || !retryNow {
+ log.WithError(err).WithField("user_id", userID).Warn("File count initialization ineligible")
+ return cleaned
+ }
+ initialized, err = c.UsageRepo.InitializeFileCounts(ctx, userID)
+ }
+ if errors.Is(err, repo.ErrFileCountIneligible) {
log.WithError(err).WithField("user_id", userID).Warn("File count initialization ineligible")
- return cleaned
+ return false
}
if err != nil {
log.WithError(err).WithField("user_id", userID).Error("Failed to initialize file counts")
diff --git a/server/pkg/repo/trash.go b/server/pkg/repo/trash.go
index ff278c2906..e45c8e9b39 100644
--- a/server/pkg/repo/trash.go
+++ b/server/pkg/repo/trash.go
@@ -20,7 +20,7 @@ const (
TrashDiffLimit = 2500
TrashBatchSize = 1000
- staleDeletedFileLimit = 10
+ StaleDeletedFileLimit = 10
EmptyTrashQueueItemSeparator = "::"
)
@@ -253,7 +253,7 @@ func (t *TrashRepository) GetStaleDeletedFileIDs(ctx context.Context, userID int
JOIN trash t ON t.file_id = f.file_id
WHERE c.owner_id = $1 AND f.owner_id = $1 AND t.user_id = $1
AND t.is_deleted = TRUE AND t.is_restored = FALSE
- LIMIT $2`, userID, staleDeletedFileLimit)
+ LIMIT $2`, userID, StaleDeletedFileLimit)
if err != nil {
return nil, stacktrace.Propagate(err, "")
}