From 3f88f5229126ddbf3307c0aa831d22e952f5072a Mon Sep 17 00:00:00 2001 From: Mohammad Abdul Sahil <127765312+abdulsaheel@users.noreply.github.com> Date: Fri, 20 Nov 2026 07:58:05 +0530 Subject: [PATCH] import: stage only the target night, not the buffered evening too --- lib/compute/derivation_engine.dart | 7 ++++++- test/derive_day_window_test.dart | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/compute/derivation_engine.dart b/lib/compute/derivation_engine.dart index 8133baa6c..233063874 100644 --- a/lib/compute/derivation_engine.dart +++ b/lib/compute/derivation_engine.dart @@ -6659,7 +6659,12 @@ class DerivationEngine { await Future.delayed(const Duration(milliseconds: 250)); } return _withRunLock(0, () async { - final days = calendarDays(sub); + // One date (every NoopIngest call): stage only that night, like the + // live path. The full walk re-staged the buffered prior evening on the + // UI isolate and then threw it away, so an import paid two nights per day. + final target = dates.length == 1 ? dates.single : null; + final days = calendarDays(sub, + targetDay: target, skipUnusedDays: target != null); final dataNowSec = sub.lastTs ?? 0; var done = 0; for (var i = 0; i < days.length; i++) { diff --git a/test/derive_day_window_test.dart b/test/derive_day_window_test.dart index a98a35d88..5dc39d62d 100644 --- a/test/derive_day_window_test.dart +++ b/test/derive_day_window_test.dart @@ -360,4 +360,19 @@ void main() { ); expect(await Future.wait([a, b]), [1, 1]); }); + + // The importer hands over the prior evening plus the target date. Only the + // target is kept, so only the target night should be staged. + test('an import stages only the requested date, not the buffered evening', + () async { + final eve = DateTime(2026, 4, 24, 20).millisecondsSinceEpoch ~/ 1000; + debugSegmentedDayCount = 0; + final n = await DerivationEngine().deriveImportedDays( + _synthDay(eve, 16 * 3600), + const Profile(), + {'2026-04-25'}, + ); + expect(n, 1); + expect(debugSegmentedDayCount, 1); + }); }