Skip to content

Conversation

@grittypuffy
Copy link
Contributor

Description

This PR adds support for sending notification email for users who are about to exceed storage (95% of utilization incl. bonus, etc.) and deletes notification if the subscription has been altered (deletion, upgrade, downgrade)

@grittypuffy grittypuffy requested a review from ua741 August 11, 2025 05:51
@grittypuffy grittypuffy enabled auto-merge August 11, 2025 05:52
Comment on lines +178 to +182
// deletion for storage limit exceeding email notification
c.NotificationHistoryRepo.DeleteLastNotification(userID, StorageLimitExceedingTemplateID)

// deletion for storage limit exceeded email notification
c.NotificationHistoryRepo.DeleteLastNotification(userID, StorageLimitExceededTemplateID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of cancellation, I think we would want to reset it on account upgrade?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user cancels their subscription and resubscribes, it will be cleaner to handle that edge case, that's why I did this. Will check on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they got a notification, and then cancel.. will they again get notification?
I am thinking of this flow

  • User is exceeding storage, already got an email
  • They cancel.. again they will get an email..
  • They upgrade/re-sub. will they again get email?

Just not doing anything on cancellation might be enough. I would be missing certain cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it goes with the flow you have described, for any action on their subscription (incl. cancellation) the notification must be sent again for proactively addressing their storage quota usage. That's why I handled the notification with cancellation too, it's an edge case.

Comment on lines 29 to 36
var lastNotificationTime sql.NullInt64
row := repo.DB.QueryRow(`SELECT MAX(sent_time) FROM notification_history WHERE user_id = $1 and template_id = $2`, userID, templateID)
err := row.Scan(&lastNotificationTime)
if err != nil {
return stacktrace.Propagate(err, "")
}
if lastNotificationTime.Valid {
_, err := repo.DB.Exec(`
DELETE FROM notification_history
WHERE user_id = $1 AND template_id = $2 AND sent_time = $3
`, userID, templateID, lastNotificationTime.Int64)

if err != nil {
return stacktrace.Propagate(err, "failed to delete last notification")
}
}
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just call delete query instead of querying for last instance. It will simplify code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, intended to remove those lines, will do.

@grittypuffy grittypuffy force-pushed the server/email-retention-v2 branch from 07d0e7b to 22fa8aa Compare August 13, 2025 17:25
Comment on lines +433 to +435
if (storageConsumed) <= (95 * (subStorage + refBonusStorage + addOnBonusStorage) / 100) {
continue
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If before cron runs (even for existing users), if storageConsumed is > 100%, will they get two emails.. one for exceeding and another for exceeded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants