Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/soak.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: soak

# Database growth + load-time soak (test/db_growth_soak_test.dart). Too slow
# for every PR — a simulated day costs ~15-30 s through the real ingest — so it
# runs nightly and on demand, and the per-day size report is kept as an
# artifact either way.
on:
schedule:
- cron: '30 2 * * *'
workflow_dispatch:
inputs:
days:
description: Live days to simulate
default: '30'
history:
description: History lengths (days) to time loads at
default: '30,180,365,730'

# Per event, so a manual run never cancels the nightly one before its report
# is uploaded.
concurrency:
group: soak-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

permissions:
contents: read

jobs:
soak:
runs-on: ubuntu-latest
timeout-minutes: 120
strategy:
fail-fast: false
matrix:
device: [gen4, mg]
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

# Same pin as test.yml, for the same reasons.
- uses: subosito/flutter-action@v2
with:
flutter-version: 3.41.6
channel: stable
cache: true

- name: Guard — the lock pins sibling commits, and the pins aren't stale
run: bash .github/scripts/check_sibling_pins.sh

- name: Install dependencies
run: flutter pub get

- name: Soak (${{ matrix.device }})
env:
OPENSTRAP_SOAK: '1'
SOAK_DEVICE: ${{ matrix.device }}
SOAK_DAYS: ${{ inputs.days || '30' }}
SOAK_HISTORY: ${{ inputs.history || '30,180,365,730' }}
run: flutter test --concurrency=1 --reporter=expanded test/db_growth_soak_test.dart

- name: Keep the size report
if: always()
uses: actions/upload-artifact@v4
with:
name: db-growth-${{ matrix.device }}
path: build/soak/db_growth.csv
if-no-files-found: ignore
28 changes: 19 additions & 9 deletions lib/data/db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9619,11 +9619,21 @@ class LocalDb {
/// THIS rather than writing its own `MAX(algo_version)` — the pattern had
/// already reappeared at five readers and two views, and the ceiling has to
/// be on all of them or it is on none of them.
static const String _servedDayJoin =
'JOIN (SELECT day_id, MAX(algo_version) AS v FROM day_result '
'WHERE algo_version <= $_servedAlgoCeiling GROUP BY day_id) m '
static const String _servedDayJoin = 'JOIN ($_servedVersions) m $_servedOn';
static const String _servedVersions =
'SELECT day_id, MAX(algo_version) AS v FROM day_result '
'WHERE algo_version <= $_servedAlgoCeiling GROUP BY day_id';
static const String _servedOn =
'ON r.day_id = m.day_id AND r.algo_version = m.v';

/// [_servedDayJoin] for the newest N days only (bind N). A LIMIT on the
/// outer query comes after the join and its sort, so SQLite fetched and
/// sorted EVERY day's row, bundle and all, to return N: a 30-day read went
/// from ~60 ms to 250-600 ms between 30 and 730 days of history. Choosing
/// the days first, from the covering index, leaves N rows to fetch.
static const String _servedNewestDaysJoin =
'JOIN ($_servedVersions ORDER BY day_id DESC LIMIT ?) m $_servedOn';

/// The result row for one day_id at the highest version this build serves
/// (see [_servedAlgoCeiling]), with a normalized `date` alias for callers.
/// Null if absent.
Expand Down Expand Up @@ -9824,8 +9834,8 @@ class LocalDb {
// For each day_id pick MAX(algo_version), then join back for the full row.
final rows = await db.rawQuery(
'SELECT r.* FROM day_result r '
'$_servedDayJoin '
'ORDER BY r.day_id DESC LIMIT ?',
'$_servedNewestDaysJoin '
'ORDER BY r.day_id DESC',
[limit],
);
return [for (final r in rows) _withDate(r)];
Expand All @@ -9849,8 +9859,8 @@ class LocalDb {
'SELECT r.day_id, r.algo_version, r.computed_at, r.finalized, '
'r.skipped, r.partial, r.rhr, r.rmssd, r.readiness '
'FROM day_result r '
'$_servedDayJoin '
'ORDER BY r.day_id DESC LIMIT ?',
'$_servedNewestDaysJoin '
'ORDER BY r.day_id DESC',
[limit],
);
return [for (final r in rows) _withDate(r)];
Expand Down Expand Up @@ -9896,8 +9906,8 @@ class LocalDb {
final rows = await db.rawQuery(
'SELECT r.day_id${cols.isEmpty ? '' : ', ${cols.join(', ')}'} '
'FROM day_result r '
'$_servedDayJoin '
'ORDER BY r.day_id DESC LIMIT ?',
'$_servedNewestDaysJoin '
'ORDER BY r.day_id DESC',
[limit],
);
return [for (final r in rows) _withDate(r)];
Expand Down
Loading
Loading