mirror of
https://github.com/simple-login/app.git
synced 2024-11-15 05:07:33 +08:00
50c130a3a3
* Store the latest email_log id in the alias to simplify dashboard query * Fix test * Add script to migrate users last email_log_id to alias * Always update the alias last_email_log_id automatically * Only set the alias_id if it is set * Fix test with randomization * Fix notification test * Also remove explicit set on tests * Rate limit alias creation to prevent abuse (#2021) * Rate limit alias creation to prevent abuse * Limit in secs * Calculate bucket time * fix exception * Tune limits * Move rate limit config to configuration (#2023) * Fix dropdown item in header (#2024) * Add option for admin to stop trial (#2026) * Fix: if redis is not configured do not enable rate limit (#2027) * support product IDs for the new Mac app (#2028) Co-authored-by: Son NK <son@simplelogin.io> * Add metrics to rate limit (#2029) * Order domains alphabetically when retrieving them (#2030) * Removed unused import * Remove debug info --------- Co-authored-by: D-Bao <49440133+D-Bao@users.noreply.github.com> Co-authored-by: Son Nguyen Kim <son.nguyen@proton.ch> Co-authored-by: Son NK <son@simplelogin.io>
21 lines
739 B
Python
21 lines
739 B
Python
#!/usr/bin/env python3
|
|
|
|
from sqlalchemy import func
|
|
|
|
from app.models import Alias
|
|
from app.db import Session
|
|
|
|
max_alias_id = Session.query(func.max(Alias.id)).scalar()
|
|
|
|
step = 1000
|
|
el_query = "SELECT alias_id, MAX(id) from email_log where alias_id>=:start AND alias_id < :end GROUP BY alias_id"
|
|
alias_query = "UPDATE alias set last_email_log_id = :el_id where id = :alias_id"
|
|
updated = 0
|
|
for batch_start in range(0, max_alias_id, step):
|
|
rows = Session.execute(el_query, {"start": batch_start, "end": batch_start + step})
|
|
for row in rows:
|
|
Session.execute(alias_query, {"alias_id": row[0], "el_id": row[1]})
|
|
Session.commit()
|
|
updated += 1
|
|
print(f"\rAlias {batch_start}/{max_alias_id} {updated}")
|
|
print("")
|