Skip to content

Note reminders index fix - #2627

Merged
amirbiron merged 4 commits into
mainfrom
cursor/note-reminders-index-fix-73f7
Jan 8, 2026
Merged

amirbiron merged 4 commits into
mainfrom
cursor/note-reminders-index-fix-73f7

Conversation

@amirbiron

@amirbiron amirbiron commented Jan 8, 2026 •

Copy link
Copy Markdown
Owner

📋 מה תוקן (ולמה זה יפיל את ה־Cascade)

1) תיקון האינדקס החלקי ב־note_reminders (הגורם הראשי)

תיקנתי את ה־partial index כך שלא ישתמש ב־$ne/$not בתוך partialFilterExpression (שמונגו לא תומך בהם), ועברתי ל־needs_push: True.

בנוסף, שיניתי את סדר המפתחות באינדקס כדי להתאים ל־sort("remind_at", 1) + limit (כלומר remind_at ראשון).

שינוי ב־ database/manager.py


2) כדי שהאינדקס באמת ינוצל: הפולינג הפך ל־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.py


3) קאש ל־/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ים.

Open in Cursor Open in Web


Note

Improves reminder delivery performance and stability, reduces DB load, and tidies logs.

  • Indexing: Adjusts note_reminders partial index to partialFilterExpression={"ack_at": None, "needs_push": True} and reorders keys to ("remind_at", 1), ("status", 1) for efficient sort+limit (in database/manager.py).
  • Polling logic: Replaces single $or query with two-phase fetch (new needs_push=True first, then limited legacy without needs_push), merges de-duped and globally sorts by remind_at (in webapp/push_api.py).
  • Sender singletons: Uses flock lock file to prevent multiple background sender loops across workers (in webapp/push_api.py).
  • Public stats cache: Adds 5–10 min caching to api_public_stats with dynamic TTL and cached flag (in webapp/app.py).
  • Concurrency default: Defaults WEB_CONCURRENCY=1 when unspecified in unified container runs to avoid duplicate background work (in scripts/run_all.sh).
  • Profiler logs: Drops redundant free-form slow query log line; rely on structured emit_event only (in services/query_profiler_service.py).

Written by Cursor Bugbot for commit 2767c93. This will update automatically on new commits. Configure here.

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>
@cursor

cursor Bot commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

github-actions Bot commented Jan 8, 2026 •

Copy link
Copy Markdown
Contributor

🧯 Dangerous deletes guard report

Policy: see .cursorrules — dangerous deletions are blocked unless wrapped safely.

Summary:

  • Flagged findings (blocking): 0
    0
  • Excluded matches (not blocking): 15
  • Total matches (all files): 125

Flagged findings (file:line:snippet):
(none)

Excluded matches (by path pattern)
./Dockerfile:42:    rm -rf /var/lib/apt/lists/*
./Dockerfile:121:    rm -rf /var/lib/apt/lists/*
./webapp/static/js/md_preview.bundle.js.map:4:  "sourcesContent": ["// Markdown-it plugin to render GitHub-style task lists; see\n//\n// https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments\n// https://github.com/blog/1825-t … [truncated]
./README.md:844:find . -name "__pycache__" -exec rm -rf {} +
./docs/DOCUMENTATION_GUIDE.md:453:rm -rf _build
./docs/Makefile:24:	rm -rf $(BUILDDIR)
./node_modules/mermaid/dist/chunks/mermaid.core/chunk-KS23V3DP.mjs.map:4:  "sourcesContent": ["{\n  \"name\": \"mermaid\",\n  \"version\": \"11.12.0\",\n  \"description\": \"Markdown-ish syntax for generating flowcharts, mindmaps, sequence  … [truncated]
./node_modules/mermaid/dist/chunks/mermaid.esm.min/chunk-4HFYJGYH.mjs.map:4:  "sourcesContent": ["{\n  \"name\": \"mermaid\",\n  \"version\": \"11.12.0\",\n  \"description\": \"Markdown-ish syntax for generating flowcharts, mindmaps, sequen … [truncated]
./node_modules/mermaid/dist/chunks/mermaid.esm.min/chunk-4HFYJGYH.mjs:1:var r={name:"mermaid",version:"11.12.0",description:"Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graph … [truncated]
./node_modules/mermaid/dist/chunks/mermaid.esm/chunk-2M32CCKP.mjs.map:4:  "sourcesContent": ["{\n  \"name\": \"mermaid\",\n  \"version\": \"11.12.0\",\n  \"description\": \"Markdown-ish syntax for generating flowcharts, mindmaps, sequence d … [truncated]
./node_modules/mermaid/dist/mermaid.min.js:1524:`,"getStyles"),c1e=RQe});var h1e={};dr(h1e,{diagram:()=>NQe});var NQe,f1e=N(()=>{"use strict";$ge();a1e();l1e();u1e();NQe={parser:Fge,db:n1e,renderer:o1e,styles:c1e}});var m1e,g1e=N(()=>{"use  … [truncated]
./node_modules/mermaid/dist/mermaid.js.map:4:  "sourcesContent": ["/**\n* Default values for dimensions\n*/\nconst defaultIconDimensions = Object.freeze({\n\tleft: 0,\n\ttop: 0,\n\twidth: 16,\n\theight: 16\n});\n/**\n* Default values for tr … [truncated]
./node_modules/mermaid/dist/mermaid.min.js.map:4:  "sourcesContent": ["/**\n* Default values for dimensions\n*/\nconst defaultIconDimensions = Object.freeze({\n\tleft: 0,\n\ttop: 0,\n\twidth: 16,\n\theight: 16\n});\n/**\n* Default values fo … [truncated]
./node_modules/katex/package.json:153:    "build": "rimraf dist/ && mkdirp dist && cp README.md dist && rollup -c --failAfterWarnings && webpack && node update-sri.js package dist/README.md",
./node_modules/katex/src/fonts/Makefile:139:	rm -rf pfa ff otf ttf woff woff2

@github-actions

github-actions Bot commented Jan 8, 2026 •

Copy link
Copy Markdown
Contributor

⏱️ Performance report

(No performance test durations collected. Mark tests with @pytest.mark.performance.)

@github-actions

github-actions Bot commented Jan 8, 2026 •

Copy link
Copy Markdown
Contributor

📖 Documentation Preview

The documentation has been built successfully!

To view locally:

  1. Download the artifacts
  2. Extract the zip file
  3. Open index.html in your browser

@sentry

sentry Bot commented Jan 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread webapp/push_api.py
cursoragent and others added 2 commits January 8, 2026 11:41
Co-authored-by: amirbiron <amirbiron@gmail.com>
Co-authored-by: amirbiron <amirbiron@gmail.com>
@amirbiron
amirbiron marked this pull request as draft January 8, 2026 11:55
Co-authored-by: amirbiron <amirbiron@gmail.com>
@amirbiron
amirbiron marked this pull request as ready for review January 8, 2026 11:55
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@amirbiron
amirbiron merged commit 547e1da into main Jan 8, 2026
39 checks passed
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