diet-guard/diet_guard
Krzysztof kuhy Rudnicki 6258b35f88
Some checks are pending
file-length / file length <= 250 lines (push) Waiting to run
pre-commit / pre-commit (push) Waiting to run
Tests / test (3.10) (push) Waiting to run
Tests / test (3.11) (push) Waiting to run
Tests / test (3.12) (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
perf(sync): hoist the device listing and stop the curated-bank 404 storm
Two independent costs in the background tick, both pure waste.

`list_directory` was called four times per tick -- once by the log pull and
once by each of the three bank syncs. It is the single most expensive call
in a tick at ~445ms mirrored (the GitHub half alone is ~360ms), so that was
~1.3s spent asking the same question four times. It is now listed once in
`run_sync` and passed down.

The curated-bank loop was worse: 17s and 62 requests to fetch *zero* useful
bytes. Firebase returns None for every peer's `food_bank_manual.json`, so
`MirrorSyncClient.get_file_text` treated each miss as "this device has not
migrated yet" and fell through to GitHub, which answers `{}` after ~320ms.
`_primary_only_text` skips that per-peer fallthrough for this one artifact.

Checked before narrowing rather than assumed, because CLAUDE.md requires
both halves of the food bank to sync: reading every peer's curated bank
straight off the mirror found 23 absent, 2 empty, and zero non-empty. No
curated food exists on the mirror alone. The probe is written into the
docstring so it can be re-run before anyone widens this again.

Measured end to end: manual-bank loop 17.0s -> 3.4s, full tick ~27s -> 15.2s,
log/bank/peer state unchanged (441 entries, 117 foods, 22 peers).

`_pull_remote_logs` now returns the revisions it saw instead of mutating a
caller-supplied dict, which keeps it under the argument limit and makes the
data flow visible at the call site.

Deliberately NOT done: revision-skipping the derived food bank. `run_sync`
rebuilds that bank from the merged log immediately before syncing it, so
unlike the log the peer records are not durably held locally -- skipping a
peer would drop its counts from the pushed bank and oscillate under
max-count-wins. Verified empirically: the on-disk bank and a pure log-derived
rebuild are identical (117 foods, 0 differing counts), and the 2 foods peers
know that the local bank lacks are discarded by the existing `if name in
local` filter anyway. The loop is off every interactive path now, so the
remaining cost is background-only.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LJ5YnA3CERitQ57HjMu2Qz
2026-08-21 13:16:08 +02:00
..
sync_merge Sync the meal schedule as sched: fields on the budget record 2026-08-16 14:49:08 +02:00
tests perf(sync): hoist the device listing and stop the curated-bank 404 storm 2026-08-21 13:16:08 +02:00
__init__.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
__main__.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_averages_periods.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_averages_report.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_averages.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_budget_biometrics.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_budget_derived.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_budget_history.py Split _sync.py and its tests; extract the gate fixtures from conftest 2026-08-15 18:51:18 +02:00
_budget.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_calendar_view.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_cli_args.py Make PC sync event-driven; retire the 15-min timer 2026-08-15 19:21:30 +02:00
_cli_averages.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_cli_gate.py perf(gate): narrow the pre-lock pull and defer the heavy imports 2026-08-21 12:58:44 +02:00
_cli_init.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_cli_log.py Read the meal schedule from a forward-only history (Python) 2026-08-16 14:28:22 +02:00
_cli_sync.py perf(gate): narrow the pre-lock pull and defer the heavy imports 2026-08-21 12:58:44 +02:00
_cli.py Read the meal schedule from a forward-only history (Python) 2026-08-16 14:28:22 +02:00
_coerce.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_constants.py perf(gate): unfreeze "Fetch from sync" and bound the interactive timeout 2026-08-21 13:07:37 +02:00
_daystatus.py Show weekly and monthly average intake on both devices 2026-08-09 14:59:40 +02:00
_device.py Split _sync.py and its tests; extract the gate fixtures from conftest 2026-08-15 18:51:18 +02:00
_estimator_off.py perf(gate): narrow the pre-lock pull and defer the heavy imports 2026-08-21 12:58:44 +02:00
_estimator.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_foodbank_manual.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_foodbank_rebuild.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_foodbank_search.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_foodbank.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_fuzzy.py feat(diet_guard): add meal-logging screen-lock gate with trigger fix 2026-06-10 22:32:39 +02:00
_gate.py Read the meal schedule from a forward-only history (Python) 2026-08-16 14:28:22 +02:00
_gatelock_budgetedit.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_gatelock_calendar_schedule.py Let the PC gate set the eating window and meal count 2026-08-16 15:02:35 +02:00
_gatelock_calendar_types.py Let the PC gate set the eating window and meal count 2026-08-16 15:02:35 +02:00
_gatelock_calendar_ui.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_calendar_widgets.py Let the PC gate set the eating window and meal count 2026-08-16 15:02:35 +02:00
_gatelock_calendar.py Let the PC gate set the eating window and meal count 2026-08-16 15:02:35 +02:00
_gatelock_core.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_gatelock_dashboard.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_gatelock_fetch.py perf(gate): unfreeze "Fetch from sync" and bound the interactive timeout 2026-08-21 13:07:37 +02:00
_gatelock_fields.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_groups.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_layout.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_lockfile.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_mealflow.py perf(gate): unfreeze "Fetch from sync" and bound the interactive timeout 2026-08-21 13:07:37 +02:00
_gatelock_nutrition.py Split _state.py and _tk_fakes.py; make the food-log redirect fail closed 2026-08-15 20:21:26 +02:00
_gatelock_scheduleedit.py Let the PC gate set the eating window and meal count 2026-08-16 15:02:35 +02:00
_gatelock_spacing.py Migrate diet_guard to gatelock v0.2.0 per-output locking 2026-07-25 16:56:13 +02:00
_gatelock_support.py feat: split oversized modules for 500-line limit, fix kasa coverage gap 2026-06-14 07:19:37 +02:00
_gatelock_typography.py Make the meal gate usable without a pointer on a 1366x768 screen 2026-07-30 16:21:27 +02:00
_gatelock_ui_types.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_gatelock_ui.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_widgetgroups.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock.py Queue behind stronger lockers; bump gatelock to v0.7.1 2026-08-21 13:06:19 +02:00
_mcp_read.py Read the meal schedule from a forward-only history (Python) 2026-08-16 14:28:22 +02:00
_mcp_server.py Make PC sync event-driven; retire the 15-min timer 2026-08-15 19:21:30 +02:00
_mcp.py Read the meal schedule from a forward-only history (Python) 2026-08-16 14:28:22 +02:00
_meal_schedule_store.py Read the meal schedule from a forward-only history (Python) 2026-08-16 14:28:22 +02:00
_meal_schedule.py Derive meal slots from an eating window and a meal count 2026-08-16 14:21:12 +02:00
_portions.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_resolve.py Split the last seven Python files; extend the redirect guard to all five paths 2026-08-15 20:37:05 +02:00
_slots.py Read the meal schedule from a forward-only history (Python) 2026-08-16 14:28:22 +02:00
_state_sync.py Split _state.py and _tk_fakes.py; make the food-log redirect fail closed 2026-08-15 20:21:26 +02:00
_state_today.py Split _state.py and _tk_fakes.py; make the food-log redirect fail closed 2026-08-15 20:21:26 +02:00
_state.py Split _state.py and _tk_fakes.py; make the food-log redirect fail closed 2026-08-15 20:21:26 +02:00
_sync_banks.py perf(sync): hoist the device listing and stop the curated-bank 404 storm 2026-08-21 13:16:08 +02:00
_sync_client.py perf(gate): unfreeze "Fetch from sync" and bound the interactive timeout 2026-08-21 13:07:37 +02:00
_sync_errors.py Split _sync.py and its tests; extract the gate fixtures from conftest 2026-08-15 18:51:18 +02:00
_sync_events.py perf(gate): narrow the pre-lock pull and defer the heavy imports 2026-08-21 12:58:44 +02:00
_sync_paths.py Split _sync.py and its tests; extract the gate fixtures from conftest 2026-08-15 18:51:18 +02:00
_sync_refresh.py perf(gate): unfreeze "Fetch from sync" and bound the interactive timeout 2026-08-21 13:07:37 +02:00
_sync.py perf(sync): hoist the device listing and stop the curated-bank 404 storm 2026-08-21 13:16:08 +02:00
_test_guard.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00