π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[server] Clean up old logic for collection diff
Neeraj Guptab030c4e1820b
diff --git a/server/pkg/api/collection.go b/server/pkg/api/collection.goindex e810098cac..dbfe54abfb 100644--- a/server/pkg/api/collection.go+++ b/server/pkg/api/collection.go@@ -65,25 +65,7 @@ func (h *CollectionHandler) GetCollectionByID(c *gin.Context) {// Deprecated: Remove once rps goes to 0.// Get returns the list of collections accessible to a user.func (h *CollectionHandler) Get(c *gin.Context) {- userID := auth.GetUserID(c.Request.Header)- sinceTime, _ := strconv.ParseInt(c.Query("sinceTime"), 10, 64)-- app := auth.GetApp(c)-- // TODO: Compute both with a single query- ownedCollections, err := h.Controller.GetOwned(userID, sinceTime, app)- if err != nil {- handler.Error(c, stacktrace.Propagate(err, "Failed to get owned collections"))- return- }- sharedCollections, err := h.Controller.GetSharedWith(userID, sinceTime, app)- if err != nil {- handler.Error(c, stacktrace.Propagate(err, "Failed to get shared collections"))- return- }- c.JSON(http.StatusOK, gin.H{- "collections": append(ownedCollections, sharedCollections...),- })+ h.GetV2(c)}// GetV2 returns the list of collections accessible to a userdiff --git a/server/pkg/controller/collections/diff.go b/server/pkg/controller/collections/diff.goindex 59d71e55ff..eb00ff779b 100644--- a/server/pkg/controller/collections/diff.go+++ b/server/pkg/controller/collections/diff.go@@ -1,46 +1,10 @@package collectionsimport (- "encoding/json""github.com/ente-io/museum/ente""github.com/ente-io/stacktrace"- "github.com/google/go-cmp/cmp"- "github.com/google/go-cmp/cmp/cmpopts"- log "github.com/sirupsen/logrus"- "runtime/debug")-// GetOwned returns the list of collections owned by a user-func (c *CollectionController) GetOwned(userID int64, sinceTime int64, app ente.App) ([]ente.Collection, error) {- collections, err := c.CollectionRepo.GetCollectionsOwnedByUser(userID, sinceTime, app)- if err != nil {- return nil, stacktrace.Propagate(err, "")- }- go func() {- defer func() {- if r := recover(); r != nil {- log.Errorf("Panic caught: %s, stack: %s", r, string(debug.Stack()))- }- }()- collectionsV2, errV2 := c.CollectionRepo.GetCollectionsOwnedByUserV2(userID, sinceTime, app)- if errV2 != nil {- log.WithError(errV2).Error("failed to fetch collections using v2")- }- isEqual := cmp.Equal(collections, collectionsV2, cmpopts.SortSlices(func(a, b ente.Collection) bool { return a.ID < b.ID }))- if !isEqual {- jsonV1, _ := json.Marshal(collections)- jsonV2, _ := json.Marshal(collectionsV2)- log.WithFields(log.Fields{- "v1": string(jsonV1),- "v2": string(jsonV2),- }).Error("collections diff didn't match")- } else {- log.Info("collections diff matched")- }- }()- return collections, nil-}-// GetOwnedV2 returns the list of collections owned by a user using optimized queryfunc (c *CollectionController) GetOwnedV2(userID int64, sinceTime int64, app ente.App) ([]ente.Collection, error) {collections, err := c.CollectionRepo.GetCollectionsOwnedByUserV2(userID, sinceTime, app)diff --git a/server/pkg/repo/collection.go b/server/pkg/repo/collection.goindex f7ddcfeced..c1c75b963e 100644--- a/server/pkg/repo/collection.go+++ b/server/pkg/repo/collection.go@@ -5,7 +5,6 @@ import ("database/sql""fmt""strconv"- "strings"t "time""github.com/prometheus/client_golang/prometheus"@@ -102,54 +101,6 @@ func (repo *CollectionRepository) GetCollectionByType(userID int64, collectionTyreturn c, nil}-// GetCollectionsOwnedByUser returns the list of collections that a user owns-// todo: refactor this method-func (repo *CollectionRepository) GetCollectionsOwnedByUser(userID int64, updationTime int64, app ente.App) ([]ente.Collection, error) {- rows, err := repo.DB.Query(`- SELECT collections.collection_id, collections.owner_id, collections.encrypted_key, collections.key_decryption_nonce, collections.name, collections.encrypted_name, collections.name_decryption_nonce, collections.type, collections.app, collections.attributes, collections.updation_time, collections.is_deleted, collections.magic_metadata, collections.pub_magic_metadata- FROM collections- WHERE collections.owner_id = $1 AND collections.updation_time > $2 AND app = $3`, userID, updationTime, strings.ToLower(string(app)))- if err != nil {- return nil, stacktrace.Propagate(err, "")- }- defer rows.Close()- collectionIDs := make([]int64, 0)- collections := make([]ente.Collection, 0)- result := make([]ente.Collection, 0)- for rows.Next() {- var c ente.Collection- var name, encryptedName, nameDecryptionNonce sql.NullString- if err := rows.Scan(&c.ID, &c.Owner.ID, &c.EncryptedKey, &c.KeyDecryptionNonce, &name, &encryptedName, &nameDecryptionNonce, &c.Type, &c.App, &c.Attributes, &c.UpdationTime, &c.IsDeleted, &c.MagicMetadata, &c.PublicMagicMetadata); err != nil {- return collections, stacktrace.Propagate(err, "")- }- if name.Valid && len(name.String) > 0 {- c.Name = name.String- } else {- c.EncryptedName = encryptedName.String- c.NameDecryptionNonce = nameDecryptionNonce.String- }- // TODO: Pull this information in the previous query- sharees, err := repo.GetSharees(c.ID)- if err != nil {- return collections, stacktrace.Propagate(err, "")- }- c.Sharees = sharees- collections = append(collections, c)- collectionIDs = append(collectionIDs, c.ID)- }-- urlMap, err := repo.PublicCollectionRepo.GetCollectionToActivePublicURLMap(context.Background(), collectionIDs)- if err != nil {- return nil, stacktrace.Propagate(err, "failed to get publicURL info")- }- for _, c := range collections {- c.PublicURLs = urlMap[c.ID]- result = append(result, c)- }-- return result, nil-}-func (repo *CollectionRepository) GetCollectionsOwnedByUserV2(userID int64, updationTime int64, app ente.App) ([]ente.Collection, error) {rows, err := repo.DB.Query(`SELECT