Skip to content

armgit / ente

Public Imported from GitHub
0

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

[server] Remove dead code related to collecton trashV2

Neeraj Gupta5accf4c6a800
diff --git a/server/pkg/controller/collection.go b/server/pkg/controller/collection.go
index 4deb58db95..6e51072ada 100644
--- a/server/pkg/controller/collection.go
+++ b/server/pkg/controller/collection.go
@@ -667,7 +667,7 @@ func (c *CollectionController) TrashV3(ctx *gin.Context, req ente.TrashCollectio
return stacktrace.Propagate(err, "failed to revoke cast token")
}
// Continue with current delete flow till. This disables sharing for this collection and then queue it up for deletion
- err = c.CollectionRepo.ScheduleDelete(cID, false)
+ err = c.CollectionRepo.ScheduleDelete(cID)
if err != nil {
return stacktrace.Propagate(err, "")
}
diff --git a/server/pkg/controller/data_cleanup/controller.go b/server/pkg/controller/data_cleanup/controller.go
index d3e2c61a68..05727ff0c2 100644
--- a/server/pkg/controller/data_cleanup/controller.go
+++ b/server/pkg/controller/data_cleanup/controller.go
@@ -127,7 +127,7 @@ func (c *DeleteUserCleanupController) deleteCollections(ctx context.Context, ite
for collectionID, isAlreadyDeleted := range collectionsMap {
if !isAlreadyDeleted {
// Delete all files in the collection
- err = c.CollectionRepo.ScheduleDelete(collectionID, false)
+ err = c.CollectionRepo.ScheduleDelete(collectionID)
if err != nil {
return stacktrace.Propagate(err, fmt.Sprintf("error while deleting collection %d", collectionID))
}
diff --git a/server/pkg/controller/trash.go b/server/pkg/controller/trash.go
index 0b3d242a9e..7fde973e49 100644
--- a/server/pkg/controller/trash.go
+++ b/server/pkg/controller/trash.go
@@ -121,17 +121,6 @@ func (t *TrashController) CleanupTrashedCollections() {
t.collectionTrashRunning = false
}()
- // process delete collection request for DELETE V2
- items, err := t.QueueRepo.GetItemsReadyForDeletion(repo.TrashCollectionQueue, 100)
- if err != nil {
- log.Error("Could not fetch from collection trash queue", err)
- return
- }
- item_processed_count += len(items)
- for _, item := range items {
- t.trashCollection(item, repo.TrashCollectionQueue, true, ctxLogger)
- }
-
// process delete collection request for DELETE V3
itemsV3, err2 := t.QueueRepo.GetItemsReadyForDeletion(repo.TrashCollectionQueueV3, 100)
if err2 != nil {
@@ -140,7 +129,7 @@ func (t *TrashController) CleanupTrashedCollections() {
}
item_processed_count += len(itemsV3)
for _, item := range itemsV3 {
- t.trashCollection(item, repo.TrashCollectionQueueV3, false, ctxLogger)
+ t.trashCollection(item, repo.TrashCollectionQueueV3, ctxLogger)
}
}
@@ -221,7 +210,7 @@ func (t *TrashController) removeFilesWithVersion(trashedFiles []ente.Trash, vers
return trashedFiles[0 : i+1]
}
-func (t *TrashController) trashCollection(item repo.QueueItem, queueName string, trashOnlyExclusiveFiles bool, logger *log.Entry) {
+func (t *TrashController) trashCollection(item repo.QueueItem, queueName string, logger *log.Entry) {
cID, _ := strconv.ParseInt(item.Item, 10, 64)
collection, err := t.CollectionRepo.Get(cID)
if err != nil {
@@ -252,11 +241,7 @@ func (t *TrashController) trashCollection(item repo.QueueItem, queueName string,
}
}()
ctxLogger.Info("start trashing collection")
- if trashOnlyExclusiveFiles {
- err = t.CollectionRepo.TrashV2(cID, collection.Owner.ID)
- } else {
- err = t.CollectionRepo.TrashV3(context.Background(), cID)
- }
+ err = t.CollectionRepo.TrashV3(context.Background(), cID)
if err != nil {
ctxLogger.WithError(err).Error("failed to trash collection")
return
diff --git a/server/pkg/repo/collection.go b/server/pkg/repo/collection.go
index 952c03aa68..38700dec4d 100644
--- a/server/pkg/repo/collection.go
+++ b/server/pkg/repo/collection.go
@@ -775,27 +775,6 @@ func (repo *CollectionRepository) GetSharees(cID int64) ([]ente.CollectionUser,
return users, nil
}
-// getCollectionExclusiveFiles return a list of filesIDs that are exclusive to the collection
-func (repo *CollectionRepository) getCollectionExclusiveFiles(collectionID int64, collectionOwnerID int64) ([]int64, error) {
- rows, err := repo.DB.Query(`
- SELECT file_id
- FROM collection_files
- WHERE is_deleted=false
- AND file_id IN (
- SELECT file_id
- FROM collection_files
- WHERE is_deleted=false
- AND collection_id =$1
- )
- AND collection_id IN (SELECT collection_id from collections where owner_id = $2)
- GROUP BY file_id
- HAVING COUNT(file_id) = 1`, collectionID, collectionOwnerID)
- if err != nil {
- return make([]int64, 0), stacktrace.Propagate(err, "")
- }
- return convertRowsToFileId(rows)
-}
-
// GetCollectionFileIDs return list of fileIDs are currently present in the given collection
// and fileIDs are owned by the collection owner
func (repo *CollectionRepository) GetCollectionFileIDs(collectionID int64, collectionOwnerID int64) ([]int64, error) {
@@ -824,41 +803,6 @@ func convertRowsToFileId(rows *sql.Rows) ([]int64, error) {
return fileIDs, nil
}
-// TrashV2 removes an entry in the database for the collection referred to by `collectionID` and move all files
-// which are exclusive to this collection to trash
-// Deprecated. Please use TrashV3
-func (repo *CollectionRepository) TrashV2(collectionID int64, userID int64) error {
- ctx := context.Background()
- tx, err := repo.DB.BeginTx(ctx, nil)
- if err != nil {
- return stacktrace.Propagate(err, "")
- }
- fileIDs, err := repo.getCollectionExclusiveFiles(collectionID, userID)
- if err != nil {
- tx.Rollback()
- return stacktrace.Propagate(err, "")
- }
- items := make([]ente.TrashItemRequest, 0)
- for _, fileID := range fileIDs {
- items = append(items, ente.TrashItemRequest{
- FileID: fileID,
- CollectionID: collectionID,
- })
- }
- _, err = tx.ExecContext(ctx, `UPDATE collection_files SET is_deleted = true WHERE collection_id = $1`, collectionID)
- if err != nil {
- tx.Rollback()
- return stacktrace.Propagate(err, "")
- }
- err = repo.TrashRepo.InsertItems(ctx, tx, userID, items)
-
- if err != nil {
- tx.Rollback()
- return stacktrace.Propagate(err, "")
- }
- return tx.Commit()
-}
-
// TrashV3 move the files belonging to the collection owner to the trash
func (repo *CollectionRepository) TrashV3(ctx context.Context, collectionID int64) error {
log := logrus.WithFields(logrus.Fields{
@@ -949,11 +893,8 @@ func (repo *CollectionRepository) removeAllFilesAddedByOthers(collectionID int64
// ScheduleDelete marks the collection as deleted and queue up an operation to
// move the collection files to user's trash.
-// The deleteOnlyExcluiveFiles flag is true for v2 collection delete and is false for v3 version.
// See [Collection Delete Versions] for more details
-func (repo *CollectionRepository) ScheduleDelete(
- collectionID int64,
- deleteOnlyExcluiveFiles bool) error {
+func (repo *CollectionRepository) ScheduleDelete(collectionID int64) error {
updationTime := time.Microseconds()
ctx := context.Background()
tx, err := repo.DB.BeginTx(ctx, nil)
@@ -974,12 +915,7 @@ func (repo *CollectionRepository) ScheduleDelete(
tx.Rollback()
return stacktrace.Propagate(err, "")
}
- if deleteOnlyExcluiveFiles {
- err = repo.QueueRepo.AddItems(ctx, tx, TrashCollectionQueue, []string{strconv.FormatInt(collectionID, 10)})
- } else {
- err = repo.QueueRepo.AddItems(ctx, tx, TrashCollectionQueueV3, []string{strconv.FormatInt(collectionID, 10)})
- }
-
+ err = repo.QueueRepo.AddItems(ctx, tx, TrashCollectionQueueV3, []string{strconv.FormatInt(collectionID, 10)})
if err != nil {
tx.Rollback()
return stacktrace.Propagate(err, "")