π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix Space drip scheduling and candidate scan
Anand Baburajanf79258ccf129
diff --git a/server/space/controller/drips.go b/server/space/controller/drips.goindex c9caef373f..326b929d9b 100644--- a/server/space/controller/drips.go+++ b/server/space/controller/drips.go@@ -65,10 +65,9 @@ func (c *SpaceDripController) ProcessSpaceDrips() {}if c.LockController != nil {if !c.LockController.TryLock(spaceDripMailLock, timeutil.MicrosecondsAfterHours(24)) {- log.Info("Skipping space drip emails because another instance is running")+ log.Info("Skipping space drip emails because the daily lock is held")return}- defer c.LockController.ReleaseLock(spaceDripMailLock)}stats, err := c.processSpaceDrips(context.Background(), timeutil.Microseconds())if err != nil {diff --git a/server/space/controller/drips_test.go b/server/space/controller/drips_test.goindex 8732aebc5e..34bc220765 100644--- a/server/space/controller/drips_test.go+++ b/server/space/controller/drips_test.go@@ -6,12 +6,43 @@ import ("testing""github.com/ente/museum/internal/testutil"+ lockctrl "github.com/ente/museum/pkg/controller/lock"baserepo "github.com/ente/museum/pkg/repo"timeutil "github.com/ente/museum/pkg/utils/time"spacerepo "github.com/ente/museum/space/repo""github.com/stretchr/testify/require")+func TestProcessSpaceDripsKeepsDailyLock(t *testing.T) {+ testutil.WithServerRoot(t)+ db := testutil.RequireTestDB(t)+ testutil.ResetTables(t, db)+ t.Cleanup(func() {+ testutil.ResetTables(t, db)+ })++ repos := spacerepo.NewModule(db, nil)+ controller := &SpaceDripController{+ DripsRepo: repos.Drips,+ UserRepo: &baserepo.UserRepository{+ DB: db,+ SecretEncryptionKey: testutil.SecretEncryptionKey(),+ HashingKey: testutil.HashingKey(),+ },+ NotificationHistoryRepo: &baserepo.NotificationHistoryRepository{DB: db},+ LockController: &lockctrl.LockController{+ TaskLockingRepo: &baserepo.TaskLockRepository{DB: db},+ HostName: "space-drip-test",+ },+ }++ controller.ProcessSpaceDrips()++ var lockUntil int64+ require.NoError(t, db.QueryRow(`SELECT lock_until FROM task_lock WHERE task_name = $1`, spaceDripMailLock).Scan(&lockUntil))+ require.Greater(t, lockUntil, timeutil.Microseconds())+}+func TestSpaceDripsSendMatureProfileNudgeOnly(t *testing.T) {testutil.WithServerRoot(t)db := testutil.RequireTestDB(t)diff --git a/server/space/repo/drips.go b/server/space/repo/drips.goindex 11a652c238..7d275784e2 100644--- a/server/space/repo/drips.go+++ b/server/space/repo/drips.go@@ -132,18 +132,27 @@ func (r *DripsRepository) ListFirstPostCandidates(ctx context.Context, thresholdfunc (r *DripsRepository) ListFeedbackCandidates(ctx context.Context, threshold int64, excludeTemplateIDs []string, limit int) ([]SpaceDripCandidate, error) {rows, err := r.DB.QueryContext(ctx, `- WITH activities AS (- SELECT s.owner_id AS user_id, p.created_at AS event_at+ WITH eligible_spaces AS MATERIALIZED (+ SELECT s.space_id, s.owner_idFROM spaces sJOIN users u ON u.user_id = s.owner_id AND u.encrypted_email IS NOT NULL+ WHERE NOT EXISTS (+ SELECT 1+ FROM notification_history nh+ WHERE nh.user_id = s.owner_id+ AND nh.template_id = ANY($2)+ )+ ),+ activities AS (+ SELECT s.owner_id AS user_id, p.created_at AS event_at+ FROM eligible_spaces sJOIN space_posts p ON p.space_id = s.space_idWHERE p.created_at <= $1UNION ALLSELECT s.owner_id AS user_id, m.created_at AS event_at- FROM spaces s- JOIN users u ON u.user_id = s.owner_id AND u.encrypted_email IS NOT NULL+ FROM eligible_spaces sJOIN space_messages m ON m.sender_space_id = s.space_idWHERE m.kind = 'post_reply'AND m.created_at <= $1@@ -155,12 +164,6 @@ func (r *DripsRepository) ListFeedbackCandidates(ctx context.Context, threshold)SELECT fa.user_idFROM first_activity fa- WHERE NOT EXISTS (- SELECT 1- FROM notification_history nh- WHERE nh.user_id = fa.user_id- AND nh.template_id = ANY($2)- )ORDER BY fa.event_at ASC, fa.user_id ASCLIMIT $3`, threshold, pq.Array(excludeTemplateIDs), spaceDripCandidateLimit(limit))diff --git a/server/space/repo/drips_test.go b/server/space/repo/drips_test.goindex a1cf2a2499..099366fb61 100644--- a/server/space/repo/drips_test.go+++ b/server/space/repo/drips_test.go@@ -119,6 +119,15 @@ func TestFirstPostAndFeedbackDripCandidates(t *testing.T) {feedbackCandidates, err := module.Drips.ListFeedbackCandidates(ctx, now-7*24*timeutil.MicroSecondsInOneHour, []string{testSpaceDripFeedback7d}, 50)require.NoError(t, err)require.ElementsMatch(t, []int64{aliceID, bobID}, spaceDripCandidateUserIDs(feedbackCandidates))++ testutil.InsertNotificationHistory(t, module.Drips.DB, testutil.NotificationHistoryFixture{+ UserID: aliceID,+ TemplateID: testSpaceDripFeedback7d,+ SentTime: now,+ })+ feedbackCandidates, err = module.Drips.ListFeedbackCandidates(ctx, now-7*24*timeutil.MicroSecondsInOneHour, []string{testSpaceDripFeedback7d}, 50)+ require.NoError(t, err)+ require.Equal(t, []int64{bobID}, spaceDripCandidateUserIDs(feedbackCandidates))}func insertSpaceBrowserSession(t *testing.T, module *Module, userID int64, createdAt int64, expiresAt int64) {