π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Remove unused social counts endpoint
Neeraj Gupta8e27e722faae
diff --git a/mobile/apps/photos/lib/gateways/social/social_gateway.dart b/mobile/apps/photos/lib/gateways/social/social_gateway.dartindex 1e80e297e4..f9ab2319a2 100644--- a/mobile/apps/photos/lib/gateways/social/social_gateway.dart+++ b/mobile/apps/photos/lib/gateways/social/social_gateway.dart@@ -176,15 +176,4 @@ class SocialGateway {);return SocialDiffResponse.fromJson(response.data as Map<String, dynamic>);}-- Future<Map<int, int>> fetchCounts() async {- final response = await _enteDio.get("/comments-reactions/counts");- final countsData = response.data["counts"] as Map<String, dynamic>?;- if (countsData == null) {- return {};- }- return countsData.map(- (key, value) => MapEntry(int.parse(key), value as int),- );- }}diff --git a/mobile/apps/photos/lib/services/social_service.dart b/mobile/apps/photos/lib/services/social_service.dartindex d70880194f..164f5f23e5 100644--- a/mobile/apps/photos/lib/services/social_service.dart+++ b/mobile/apps/photos/lib/services/social_service.dart@@ -144,10 +144,6 @@ class SocialService {);}- Future<Map<int, int>> fetchCounts() async {- return socialGateway.fetchCounts();- }-({String cipher, String nonce}) encryptComment(String text,int collectionID,diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.goindex 92b0bce939..ee22b57d63 100644--- a/server/cmd/museum/main.go+++ b/server/cmd/museum/main.go@@ -678,7 +678,6 @@ func main() {storageAPI.GET("/social/diff", socialHandler.UnifiedDiff)storageAPI.GET("/social/anon-profiles", socialHandler.AnonProfiles)- storageAPI.GET("/comments-reactions/counts", socialHandler.Counts)storageAPI.GET("/comments-reactions/updated-at", socialHandler.LatestUpdates)emergencyCtrl := &emergency.Controller{diff --git a/server/pkg/api/collection_app_test.go b/server/pkg/api/collection_app_test.goindex 44039e3157..d2f470b464 100644--- a/server/pkg/api/collection_app_test.go+++ b/server/pkg/api/collection_app_test.go@@ -1,7 +1,6 @@package apiimport (- "encoding/json""fmt""net/http""net/http/httptest"@@ -15,12 +14,10 @@ import (castctrl "github.com/ente/museum/pkg/controller/cast""github.com/ente/museum/pkg/controller/collections""github.com/ente/museum/pkg/controller/public"- "github.com/ente/museum/pkg/controller/social""github.com/ente/museum/pkg/middleware""github.com/ente/museum/pkg/repo"castrepo "github.com/ente/museum/pkg/repo/cast"publicrepo "github.com/ente/museum/pkg/repo/public"- socialrepo "github.com/ente/museum/pkg/repo/social""github.com/ente/museum/pkg/utils/auth""github.com/gin-gonic/gin""github.com/patrickmn/go-cache"@@ -81,14 +78,9 @@ func TestCollectionAppIsolation(t *testing.T) {AccessCtrl: accessCtrl, CollectionRepo: collectionRepo, CastRepo: castRepo,CollectionLinkCtrl: &public.CollectionLinkController{CollectionLinkRepo: linkRepo},}}- socialHandler := &SocialHandler{Controller: &social.Controller{- CollectionRepo: collectionRepo,- CommentsRepo: &socialrepo.CommentsRepository{DB: db}, ReactionsRepo: &socialrepo.ReactionsRepository{DB: db},- }}gin.SetMode(gin.TestMode)router := gin.New()storage := router.Group("/", authMiddleware.TokenAuthMiddleware(nil), middleware.RejectAuthApp())- storage.GET("/comments-reactions/counts", socialHandler.Counts)storage.GET("/collections/:collectionID", collectionHandler.GetCollectionByID)storage.DELETE("/collections/v3/:collectionID", collectionHandler.TrashV3)request := func(method, path string, clientApp ente.App) *httptest.ResponseRecorder {@@ -103,15 +95,6 @@ func TestCollectionAppIsolation(t *testing.T) {if app == ente.Photos {otherApp = ente.Locker}- t.Run("counts", func(t *testing.T) {- response := request(http.MethodGet, "/comments-reactions/counts", app)- require.Equal(t, http.StatusOK, response.Code, response.Body.String())- var body struct {- Counts []social.CollectionCount `json:"counts"`- }- require.NoError(t, json.Unmarshal(response.Body.Bytes(), &body))- require.ElementsMatch(t, []social.CollectionCount{{CollectionID: owned[app]}, {CollectionID: shared[app]}}, body.Counts)- })t.Run("point_access", func(t *testing.T) {for _, ids := range []map[ente.App]int64{owned, shared} {for _, targetApp := range []ente.App{app, otherApp} {diff --git a/server/pkg/api/social.go b/server/pkg/api/social.goindex 59512f6820..81e8c0ea47 100644--- a/server/pkg/api/social.go+++ b/server/pkg/api/social.go@@ -83,21 +83,6 @@ func (h *SocialHandler) UnifiedDiff(c *gin.Context) {})}-func (h *SocialHandler) Counts(c *gin.Context) {- userID := auth.GetUserID(c.Request.Header)- app, ok := auth.GetAuthenticatedApp(c)- if userID <= 0 || !ok {- handler.Error(c, ente.ErrAuthenticationRequired)- return- }- counts, err := h.Controller.CountActiveCollections(c, userID, app)- if err != nil {- handler.Error(c, stacktrace.Propagate(err, ""))- return- }- c.JSON(http.StatusOK, gin.H{"counts": counts})-}-func (h *SocialHandler) LatestUpdates(c *gin.Context) {userID := auth.GetUserID(c.Request.Header)if userID <= 0 {diff --git a/server/pkg/controller/social/controller.go b/server/pkg/controller/social/controller.goindex fd55bb6450..09fee82022 100644--- a/server/pkg/controller/social/controller.go+++ b/server/pkg/controller/social/controller.go@@ -31,12 +31,6 @@ type UnifiedDiffRequest struct {RequireAccess bool}-type CollectionCount struct {- CollectionID int64 `json:"collectionID"`- Comments int64 `json:"comments"`- Reactions int64 `json:"reactions"`-}-type CollectionLatestUpdate struct {CollectionID int64 `json:"collectionID"`CommentsUpdatedAt *int64 `json:"commentsUpdatedAt,omitempty"`@@ -74,59 +68,6 @@ func (c *Controller) UnifiedDiff(ctx *gin.Context, req UnifiedDiffRequest) ([]soreturn comments, reactions, moreComments, moreReactions, nil}-func (c *Controller) CountActiveCollections(ctx context.Context, userID int64, app ente.App) ([]CollectionCount, error) {- ownedMap, err := c.CollectionRepo.GetCollectionIDsOwnedByUser(userID)- if err != nil {- return nil, stacktrace.Propagate(err, "")- }- shared, err := c.CollectionRepo.GetCollectionIDsSharedWithUser(userID)- if err != nil {- return nil, stacktrace.Propagate(err, "")- }- collectionIDs := make([]int64, 0, len(ownedMap)+len(shared))- for id := range ownedMap {- collectionIDs = append(collectionIDs, id)- }- for _, id := range shared {- if _, ok := ownedMap[id]; ok {- continue- }- collectionIDs = append(collectionIDs, id)- }- collectionIDs, err = c.CollectionRepo.FilterNonDeletedCollectionIDs(collectionIDs, app)- if err != nil {- return nil, stacktrace.Propagate(err, "")- }- if len(collectionIDs) == 0 {- return nil, nil- }- commentCounts, err := c.CommentsRepo.CountActiveByCollection(ctx, collectionIDs)- if err != nil {- return nil, stacktrace.Propagate(err, "")- }- reactionCounts, err := c.ReactionsRepo.CountActiveByCollection(ctx, collectionIDs)- if err != nil {- return nil, stacktrace.Propagate(err, "")- }- results := make([]CollectionCount, 0, len(collectionIDs))- sort.Slice(collectionIDs, func(i, j int) bool {- return collectionIDs[i] < collectionIDs[j]- })- seen := map[int64]struct{}{}- for _, id := range collectionIDs {- if _, ok := seen[id]; ok {- continue- }- seen[id] = struct{}{}- results = append(results, CollectionCount{- CollectionID: id,- Comments: commentCounts[id],- Reactions: reactionCounts[id],- })- }- return results, nil-}-func (c *Controller) LatestUpdates(ctx context.Context, userID int64, app ente.App) ([]CollectionLatestUpdate, error) {ownedMap, err := c.CollectionRepo.GetCollectionIDsOwnedByUser(userID)if err != nil {diff --git a/server/pkg/repo/social/comments.go b/server/pkg/repo/social/comments.goindex a1fa628c60..b5341babac 100644--- a/server/pkg/repo/social/comments.go+++ b/server/pkg/repo/social/comments.go@@ -209,36 +209,6 @@ func (repo *CommentsRepository) GetDiff(ctx context.Context, collectionID int64,return comments, hasMore, nil}-func (repo *CommentsRepository) CountActiveByCollection(ctx context.Context, collectionIDs []int64) (map[int64]int64, error) {- counts := make(map[int64]int64)- if len(collectionIDs) == 0 {- return counts, nil- }- rows, err := repo.DB.QueryContext(ctx, `- SELECT collection_id, COUNT(*)- FROM comments- WHERE collection_id = ANY($1)- AND is_deleted = FALSE- GROUP BY collection_id- `, pq.Array(collectionIDs))- if err != nil {- return counts, stacktrace.Propagate(err, "")- }- defer rows.Close()- for rows.Next() {- var collectionID int64- var count int64- if err := rows.Scan(&collectionID, &count); err != nil {- return counts, stacktrace.Propagate(err, "")- }- counts[collectionID] = count- }- if err := rows.Err(); err != nil {- return counts, stacktrace.Propagate(err, "")- }- return counts, nil-}-func (repo *CommentsRepository) LatestUpdateByCollection(ctx context.Context, collectionIDs []int64) (map[int64]int64, error) {results := make(map[int64]int64)if len(collectionIDs) == 0 {diff --git a/server/pkg/repo/social/reactions.go b/server/pkg/repo/social/reactions.goindex 93666ab4d0..9cbf914b1f 100644--- a/server/pkg/repo/social/reactions.go+++ b/server/pkg/repo/social/reactions.go@@ -205,37 +205,6 @@ func (repo *ReactionsRepository) GetDiff(ctx context.Context, collectionID int64return reactions, hasMore, nil}-func (repo *ReactionsRepository) CountActiveByCollection(ctx context.Context, collectionIDs []int64) (map[int64]int64, error) {- counts := make(map[int64]int64)- if len(collectionIDs) == 0 {- return counts, nil- }- rows, err := repo.DB.QueryContext(ctx, `- SELECT collection_id, COUNT(*)- FROM reactions- WHERE collection_id = ANY($1)- AND is_deleted = FALSE- GROUP BY collection_id- `, pq.Array(collectionIDs))- if err != nil {- return counts, stacktrace.Propagate(err, "")- }- defer rows.Close()-- for rows.Next() {- var collectionID int64- var count int64- if err := rows.Scan(&collectionID, &count); err != nil {- return counts, stacktrace.Propagate(err, "")- }- counts[collectionID] = count- }- if err := rows.Err(); err != nil {- return counts, stacktrace.Propagate(err, "")- }- return counts, nil-}-func (repo *ReactionsRepository) LatestUpdateByCollection(ctx context.Context, collectionIDs []int64) (map[int64]int64, error) {results := make(map[int64]int64)if len(collectionIDs) == 0 {