refactor(config): Move all state files to .madblog #22
No reviewers
Labels
No labels
activitypub
auth
bug
build
duplicate
enhancement
feeds
help wanted
invalid
markdown
new feature
question
style
webmentions
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
blacklight/madblog!22
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "refactor/unique-state-directory"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
State Directory Refactoring Plan
This document describes the plan to consolidate all Madblog-specific state under
a single configurable state directory (defaulting to
.madblog).Motivation
Currently, Madblog stores state in multiple locations within the content
directory:
.madblog/— partial state (ActivityPub sync, cache, webmentions sync)activitypub/— pubby'sFileActivityPubStoragedata (private key,followers, objects, interactions)
mentions/— webmentions markdown files (incoming/outgoing)This layout clutters the content directory with implementation details. The goal
is to:
.madblogdirectory.location (e.g., outside the content directory for backup/sync separation).
Current Layout
Source Code References
.madblog/activitypub/ActivityPubIntegration.__init__activitypub/_integration.py:65-72.madblog/cache/tags-index.jsonTagIndex.__init__tags/_index.py:163-164.madblog/webmentions_sync.jsonFileWebmentionsStorage.__init__webmentions/_storage.py:66-67activitypub/ActivityPubMixin._init_activitypubactivitypub/_mixin.py:115-125mentions/WebmentionsMixin._init_webmentionswebmentions/_mixin.py:34-36Proposed Layout
Key Changes
activitypub/→.madblog/activitypub/state/FileActivityPubStoragedata moves under.madblog.state/subdirectory keeps pubby's storage separate from Madblog'sActivityPub sync files.
mentions/→.madblog/mentions/.madblog.incoming/,outgoing/,<post-slug>/) preserved.Configurable state directory
state_dir(default:<content_dir>/.madblog)MADBLOG_STATE_DIRConfiguration
New Config Option
Environment Variable
Config Class Changes
Add to
madblog/config.py:Migration Plan
Strategy: Automatic Detection + Migration
On startup, Madblog will:
Detection Logic
Migration Implementation
Migration Location
The migration check should run early in application initialization, before any
subsystem that accesses state directories:
madblog/cli.py): Afterinit_config(), beforeapp.start().madblog/uwsgi.py): After config initialization.Suggested implementation:
New
statemodule structure:Avoiding Reprocessing of Migrated Files
Problem
Both
ActivityPubIntegrationandFileWebmentionsStorageuseStartupSyncMixinto detect new/changed content on startup. They track filemtimes in JSON cache files:
.madblog/activitypub/published_objects.json.madblog/webmentions_sync.jsonIf files are moved without preserving mtimes, or if cache files reference old
paths, the system will treat migrated files as new and reprocess them.
Solution
Preserve file mtimes during migration (shown above).
Cache files remain valid — they track content file mtimes (markdown
files in
markdown/), not state file paths. Since content files are notmoved, the caches remain valid.
Webmentions markdown files — these are output files, not input. Moving
them doesn't trigger reprocessing because:
webmentions_sync.json, which tracks the markdown source files.ActivityPub storage — pubby's
FileActivityPubStorageuses internalJSON files. Moving the entire directory preserves all internal state
(followers, objects, interactions).
Verification Steps
After migration:
published_objects.jsonandwebmentions_sync.jsonexist andcontain valid JSON.
state_dir/activitypub/state/followers/).Code Changes Required
Files to Modify
madblog/config.pystate_dirfield andresolved_state_dirpropertymadblog/state/__init__.pystatemodulemadblog/state/_state.py.pymadblog/state/_migrations.py.pymadblog/cli.pyensure_state_directory()after config initmadblog/uwsgi.pyensure_state_directory()after config initmadblog/activitypub/_mixin.pyconfig.resolved_state_dirforap_dirmadblog/activitypub/_integration.pyconfig.resolved_state_dirfor workdirmadblog/webmentions/_mixin.pyconfig.resolved_state_dirformentions_dirmadblog/webmentions/_storage.pyconfig.resolved_state_dirfor sync cachemadblog/tags/_index.pyconfig.resolved_state_dirfor cache dirPath Resolution Changes
Before:
After:
Manual Migration Script
For users who prefer manual control, provide a CLI command:
Implementation:
Testing
Unit Tests
_detect_legacy_layout()with various directorystructures.
_migrate_legacy_state()preserves:and custom
state_dir.Integration Tests
republishing.
Rollback Plan
If migration causes issues:
Move directories back manually:
Or restore from backup if available.
The migration is non-destructive in that it moves (not copies) directories, so
the original data is preserved at the new location.
Timeline
state_dirconfig option andresolved_state_dirproperty.resolved_state_dir.README.md,ARCHITECTURE.md).