Note reminders index fix - #2627
Merged
Merged
Conversation
Adds caching for the public stats API endpoint. Optimizes the note_reminders index and polling query for better performance. Co-authored-by: amirbiron <amirbiron@gmail.com>
Contributor
|
Cursor Agent can help with this pull request. Just |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Contributor
🧯 Dangerous deletes guard reportPolicy: see .cursorrules — dangerous deletions are blocked unless wrapped safely. Summary:
Flagged findings (file:line:snippet): Excluded matches (by path pattern) |
Contributor
⏱️ Performance report(No performance test durations collected. Mark tests with |
Contributor
📖 Documentation PreviewThe documentation has been built successfully!
To view locally:
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Co-authored-by: amirbiron <amirbiron@gmail.com>
Co-authored-by: amirbiron <amirbiron@gmail.com>
amirbiron
marked this pull request as draft
January 8, 2026 11:55
Co-authored-by: amirbiron <amirbiron@gmail.com>
amirbiron
marked this pull request as ready for review
January 8, 2026 11:55
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
11 of 17 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📋 מה תוקן (ולמה זה יפיל את ה־Cascade)
1) תיקון האינדקס החלקי ב־note_reminders (הגורם הראשי)
תיקנתי את ה־partial index כך שלא ישתמש ב־
$ne/$notבתוךpartialFilterExpression(שמונגו לא תומך בהם), ועברתי ל־needs_push: True.בנוסף, שיניתי את סדר המפתחות באינדקס כדי להתאים ל־
sort("remind_at", 1) + limit(כלומרremind_atראשון).שינוי ב־
database/manager.py2) כדי שהאינדקס באמת ינוצל: הפולינג הפך ל־2 שאילתות במקום $or
הבעיה הפרקטית: השאילתה עם
$or(חדשים + legacy) לא "מוכיחה" ל־MongoDB ש־needs_push=True, ולכן היא נוטה ליפול ל־COLLSCAN/תוכנית גרועה תחת עומס — גם אם יש partial index.פתרון
שאילתה 1 (מהירה): רק מסמכים חדשים עם
needs_push=True→ משתמשת ב־partial index.שאילתה 2 (best-effort): רק legacy בלי
needs_push→ מוגבלת רק לכמות שחסרה, עם de-dup לפי_id.שינוי ב־
webapp/push_api.py3) קאש ל־/api/public_stats (מוריד עוד 200–300ms קבועים מה־DB)
הוספתי קאש דרך
cache_manager(Redis אם קיים, אחרת פולבק בזיכרון) עם TTL דינמי (ברירת מחדלpublic_stats= 10 דקות).התגובה כוללת
cached: true/falseכדי שתוכלו לראות בקלות אם זה עובד.שינוי ב־
webapp/app.py✅ בדיקות
הרצה של pytest על
tests/test_push_api.pyו־tests/test_sticky_note_reminders.pyעברה בהצלחה.📝 הערה לגבי service_metrics
כבר קיימת כתיבה ב־batch ברקע ב־
monitoring/metrics_storage.py(מופעלת רק אםMETRICS_DB_ENABLED=true). אם עדיין ראיתם insert על כל בקשה – סביר שזה מגיע ממסלול כתיבה אחר או מהגדרה שמדליקה כתיבה ישירה; שווה לוודא את ה־ENVים.Note
Improves reminder delivery performance and stability, reduces DB load, and tidies logs.
note_reminderspartial index topartialFilterExpression={"ack_at": None, "needs_push": True}and reorders keys to("remind_at", 1), ("status", 1)for efficientsort+limit(indatabase/manager.py).$orquery with two-phase fetch (newneeds_push=Truefirst, then limited legacy withoutneeds_push), merges de-duped and globally sorts byremind_at(inwebapp/push_api.py).flocklock file to prevent multiple background sender loops across workers (inwebapp/push_api.py).api_public_statswith dynamic TTL andcachedflag (inwebapp/app.py).WEB_CONCURRENCY=1when unspecified in unified container runs to avoid duplicate background work (inscripts/run_all.sh).emit_eventonly (inservices/query_profiler_service.py).Written by Cursor Bugbot for commit 2767c93. This will update automatically on new commits. Configure here.