Skip to content

Conversation

shaunwarman
Copy link
Contributor

…hours

Checklist

  • I have ensured my pull request is not behind the main or master branch of the original repository.
  • I have rebased all commits where necessary so that reviewing this pull request can be done without having to merge it first.
  • I have written a commit message that passes commitlint linting.
  • I have ensured that my code changes pass linting tests.
  • I have ensured that my code changes pass unit tests.
  • I have described my pull request and the reasons for code changes along with context if necessary.

Copy link
Contributor

@titanism titanism left a comment

Choose a reason for hiding this comment

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

I think that this query will be extremely slow since it has to iterate over 300-500K+ emails at any given load. It would need optimized somehow, perhaps user model needs to have a counter (preferred approach), and then a post-save hook on Email model and an automated job that updates all users as well on an hourly basis most likely (or something similar, accurate, and efficient).

@@ -25,6 +25,16 @@ include ../../_pagination
+sortHeader('max_quota_per_alias', 'Max Qouta', '#table-users')
th(scope="col")
+sortHeader('smtp_limit', 'SMTP Limit', '#table-users')
th(scope="col")
+sortHeader('totalEmails', 'Emails Sent', '#table-users')
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to change these from camelCase to underscored to match the model. Otherwise sorting and stuff won't work properly.

}

// Add email counts to each user
// Use the optimized user model counters instead of aggregation
const usersWithEmailCounts = users.map((user) => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd get rid of all this and just use the underscored property names in the view, and then in sortHeader stuff too in the pug view, that way sorting and all works. You might want to test sorting and stuff with some fake data.


logger.info('Starting SMTP counter update job');

// Get SMTP counts per user with time-based breakdowns
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be a cursor instead of aggregate. You can refer to other jobs as to how cursor is used for iterating in a loop. Basically copy-pasta it over. Otherwise this will timeout and error since aggregate will take too long (there are millions of emails and only growing).

You also might want to keep a track of emails rejected and soft bounced or something, not sure. It would probably be very clear who the abusers are if we saw at a glance how many got rejected or bounced. Or the number with err.bounce_category of "spam" or "virus". Just sharing thoughts.

@shaunwarman shaunwarman force-pushed the feat/admin-show-smtp-list branch from 7cd1c71 to e04de69 Compare August 20, 2025 02:18
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