Skip to content

refactor(store): the Store gets its storage settings from its caller - #250

Merged
tunjayoff merged 1 commit into
mainfrom
refactor/store-durability-from-caller
Nov 21, 2026
Merged

tunjayoff merged 1 commit into
mainfrom
refactor/store-durability-from-caller

Conversation

@tunjayoff

Copy link
Copy Markdown
Owner

Closes the open item of 03-implementation-plan.md section 20: "sofascore_scraper/store/files.py gets its durability from the caller".

What changes

  • store/files.py no longer looks up sofascore_scraper.config.loader in sys.modules. It has a new public function, sofascore_scraper.store.use_settings(source). source is a function that returns the [storage] section (data_dir, durability, open_reconcile_seconds). The Store calls it on every read. If no function was given, or the function raises, the Store uses the defaults: no fsync, data, 60 s.
  • config/loader.py passes _store_settings (the active settings' storage) when the loader is imported. The Store still imports nothing from the configuration.

Why a settings function, and not a value at open_store

  • More than 20 places outside the Store open it directly (CLI commands, web deps and routes, the services context, scripts). The registry also gives every caller of a directory the same Store object.
  • files.write_bytes, publish_dir and durability_full are module functions. Other Store modules call them in about 23 places, and those calls have no Store at hand.
  • Passing a value through constructors would touch all of those places.
  • A value set once, or pushed on every rebuild, would go stale between a change and the next active() call. That affects the env-var case and default_data_dir. Asking the loader for the section on every read is exactly today's behaviour.
  • The function is given at loader import. So every process that loaded the settings loader before has the settings now, and a process without the loader still uses the defaults.

Live changes

They still apply, as before. A changed SOFASCORE_STORAGE__* variable or a reload() of sofascore.toml / overrides.json applies to the next write. The Settings page does not edit storage.durability and still marks it as needing a restart. No change users can see, so there is no CHANGELOG entry.

Tests

  • tests/test_store_files.py: the durability tests now use a fake settings function and no longer need the loader. They cover full/normal, the durable= override, the function being called on every write, the other two settings, and the defaults when no function was given or it raises.
  • tests/test_config_loader.py: the file value and a reload reach files. An env change is seen at once. FULL and full are normalised, and STORE_DURABILITY is not read. A separate process checks that importing the configuration gives the Store the settings.
  • tests/test_layers.py: no Store module mentions sys.modules.
  • Store API snapshot: tests/fixtures/store_api/use_settings.txt.
  • The ssc doctor CLI goldens now list sofascore_scraper.store, .errors, .files and .layout. Importing the configuration loads them now; none of them uses SQLite or the network.

ruff is clean. Full suite: 9883 passed, 45 skipped, also with STORE_SHADOW_CHECK=1.

Docs

01-storage.md 4.4 and item 150, 02-services.md (4.3 and the risks list), README.md (the open list) and 03 section 20 ("Done").

store/files.py no longer reads the settings loader through sys.modules. The
Store takes a function for its [storage] section (store.use_settings); the
loader passes its own when it is imported, and the Store calls it on every
read, so a changed environment or a reload still applies to the next write.
A process without the loader, or a failing function, uses the defaults.

tests/test_layers.py now also checks that no Store module looks into
sys.modules; the doctor goldens list the four light Store modules that
importing the configuration now loads.
@tunjayoff
tunjayoff merged commit 5cc0907 into main Nov 21, 2026
8 checks passed
@tunjayoff
tunjayoff deleted the refactor/store-durability-from-caller branch November 21, 2026 07:55
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.

1 participant