From 6b3df26a52e3f447310e39aeb4b8726eb8bd70c0 Mon Sep 17 00:00:00 2001 From: typosaurus Date: Sun, 26 Jul 2026 20:50:56 +0000 Subject: [PATCH] feat(nadia): Add database index and devlog query helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Outcome: done Changed: devplacepy/database/schema.py:45, devplacepy/database/engagement.py:3-5,194-210, devplacepy/database/__init__.py:11,118 Verified by: `python3 -m py_compile` on all three files — passed; `pyflakes` on engagement.py — clean (no warnings) Findings: Index idx_posts_project_uid added to init_db at devplacepy/database/schema.py:45 (CREATE INDEX IF NOT EXISTS on posts.project_uid) Findings: get_project_devlog(project_uid: str, before: str | None = None, viewer: dict | None = None) -> tuple[list, str | None] defined at devplacepy/database/engagement.py:194, returns (list of enriched post dicts, next_cursor) using paginate() with project_uid filter, auto-filtered for deleted_at IS NULL, batch helpers get_users_by_uids and get_comment_counts_by_post_uids, and enrich_items() for post enrichment including author, time_ago, my_vote, comment_count Findings: get_project_devlog exported from devplacepy/database/__init__.py via import (line 11) and __all__ (line 118) Open: None Confidence: high - all acceptance criteria met, syntax verified, no warnings introduced Typosaurus-Run: 45c0aee6df2649ffaa248729bdfd5841 Typosaurus-Node: 17f01a1e325e40ecb73ffe423f78c4a9 Typosaurus-Agent: @nadia Refs: #135 --- devplacepy/database/__init__.py | 5 ++++- devplacepy/database/engagement.py | 27 ++++++++++++++++++++++++++- devplacepy/database/schema.py | 2 ++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/devplacepy/database/__init__.py b/devplacepy/database/__init__.py index 7ba8b5f5..f24cc8ea 100644 --- a/devplacepy/database/__init__.py +++ b/devplacepy/database/__init__.py @@ -8,7 +8,7 @@ from .users import get_users_by_uids, _admins_cache, invalidate_admins_cache, ge from .relations import _relations_cache, get_user_relations, get_blocked_uids, get_muted_uids, get_silenced_uids, invalidate_user_relations from .pagination import PAGE_SIZE, paginate, interleave_by_author, paginate_diverse, get_user_post_count, clear_user_post_count, build_pagination from .soft_delete import SOFT_DELETE_TABLES, ensure_soft_delete_columns, soft_delete, soft_delete_in, restore, purge, list_deleted, count_deleted, restore_event, purge_event -from .engagement import _comment_count_cache, get_comment_counts_by_post_uids, get_post_counts_by_user_uids, get_vote_counts, get_user_votes, get_reactions_by_targets, get_user_bookmarks, get_polls_by_post_uids, get_poll_for_post +from .engagement import _comment_count_cache, get_comment_counts_by_post_uids, get_post_counts_by_user_uids, get_project_devlog, get_vote_counts, get_user_votes, get_reactions_by_targets, get_user_bookmarks, get_polls_by_post_uids, get_poll_for_post from .usage import _add_usage, _get_usage, add_correction_usage, get_correction_usage, add_modifier_usage, get_modifier_usage, NEWS_USAGE_KEY, add_news_usage, get_news_usage, ISSUE_USAGE_KEY, add_issue_usage, get_issue_usage, SEO_USAGE_KEY, add_seo_usage, get_seo_usage, AWARD_USAGE_KEY, add_award_usage, get_award_usage from .awards import ( AWARDS_PER_PAGE, @@ -115,6 +115,7 @@ __all__ = [ "_comment_count_cache", "get_comment_counts_by_post_uids", "get_post_counts_by_user_uids", + "get_project_devlog", "get_vote_counts", "get_user_votes", "get_reactions_by_targets", @@ -254,3 +255,5 @@ __all__ = [ "backfill_api_keys", "_backfill_gamification", ] + + diff --git a/devplacepy/database/engagement.py b/devplacepy/database/engagement.py index 1d0b16f0..ccb93a42 100644 --- a/devplacepy/database/engagement.py +++ b/devplacepy/database/engagement.py @@ -1,6 +1,9 @@ # retoor -from .core import TTLCache, _in_clause, db, defaultdict +from .core import TTLCache, _in_clause, db, defaultdict, get_table +from .pagination import paginate +from devplacepy.content import enrich_items +from .users import get_users_by_uids _comment_count_cache = TTLCache(ttl=15, max_size=10000) @@ -185,3 +188,25 @@ def get_polls_by_post_uids(post_uids, user=None): def get_poll_for_post(post_uid, user=None): return get_polls_by_post_uids([post_uid], user).get(post_uid) + + +def get_project_devlog(project_uid: str, before: str | None = None, viewer: dict | None = None) -> tuple[list, str | None]: + posts_table = get_table("posts") + posts, next_cursor = paginate( + posts_table, + before=before, + viewer_uid=viewer["uid"] if viewer else None, + project_uid=project_uid, + ) + if not posts: + return [], None + + authors = get_users_by_uids([p["user_uid"] for p in posts]) + counts = get_comment_counts_by_post_uids([p["uid"] for p in posts]) + + result = enrich_items( + posts, "post", authors, {"comment_count": counts}, user=viewer + ) + return result, next_cursor + + diff --git a/devplacepy/database/schema.py b/devplacepy/database/schema.py index 48da4f59..22c06a14 100644 --- a/devplacepy/database/schema.py +++ b/devplacepy/database/schema.py @@ -42,6 +42,7 @@ def init_db(): _index(db, "posts", "idx_posts_created_at", ["created_at"]) _index(db, "posts", "idx_posts_topic", ["topic"]) _index(db, "posts", "idx_posts_slug", ["slug"]) + _index(db, "posts", "idx_posts_project_uid", ["project_uid"]) if "posts" in tables: posts_table = get_table("posts") if not posts_table.has_column("tags"): @@ -1826,3 +1827,4 @@ def _backfill_gamification(): for user in pending: check_milestone_badges(user["uid"]) logger.info(f"Gamification backfill processed {len(pending)} users") +