Skip to content

Commit 08fb4f1

Browse files
authored
fix: stop rewriting the wiki every run (hash excludes Last Updated timestamp) (#35)
## Bug (in prod) `update_wiki_page` hashes the full wiki content, which begins with `**Last Updated:** <current time>` (`build_wiki_content`). Because the timestamp changes every run, `content_hash` is always new, `cached_hash == content_hash` is never true, and the page is **rewritten with a fresh revision every ~10 min even when nothing changed**. The entire `wiki_hash_cache` table is dead weight. **Impact:** needless Reddit wiki writes + revision-history spam. Not data corruption. ## Fix `get_content_hash` strips the volatile `Last Updated` line before hashing, so the change-detection hash reflects only the modlog body. Self-heals after one write post-deploy. ## Verification - timestamp-only diff → identical hash (skip now works) ✓ - body change → different hash (still writes) ✓ - existing test suite passes (no regression) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Wiki updates now skip unchanged content more reliably, reducing unnecessary edits. * Continuous and forced refresh flows are more consistent when rebuilding wiki pages. * **Bug Fixes** * Improved handling of wiki size limits and API errors for more reliable updates. * Better formatting and cleanup of moderation entries, including timestamps and removal reasons. * Faster and more dependable data lookup during wiki generation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent aef6a2e commit 08fb4f1

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

modlog_wiki_publisher.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,15 @@ def setup_database():
366366

367367

368368
def get_content_hash(content: str) -> str:
369-
"""Calculate SHA-256 hash of content"""
370-
return hashlib.sha256(content.encode("utf-8")).hexdigest()
369+
"""Calculate SHA-256 hash of content for wiki change-detection.
370+
371+
Excludes the volatile ``**Last Updated:** <timestamp>`` header line so an
372+
unchanged modlog produces a stable hash. Hashing the timestamped content
373+
made every run differ, defeating the wiki_hash_cache skip and rewriting the
374+
wiki page (a fresh revision) on every cycle even when nothing changed.
375+
"""
376+
hashable = re.sub(r"^\*\*Last Updated:\*\* .*\n", "", content, count=1)
377+
return hashlib.sha256(hashable.encode("utf-8")).hexdigest()
371378

372379

373380
def get_cached_wiki_hash(subreddit: str, wiki_page: str) -> Optional[str]:

0 commit comments

Comments
 (0)