-
Notifications
You must be signed in to change notification settings - Fork 172
feat: add smtp counts to user admin page for 1 hour, 24 hours and 72 … #419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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).
app/views/admin/users/_table.pug
Outdated
@@ -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') |
There was a problem hiding this comment.
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.
app/controllers/web/admin/users.js
Outdated
} | ||
|
||
// Add email counts to each user | ||
// Use the optimized user model counters instead of aggregation | ||
const usersWithEmailCounts = users.map((user) => ({ |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
7cd1c71
to
e04de69
Compare
…hours
Checklist