perf(inventory): lazy list, photo thumbnails, indexes, debounced reload
Scale the local inventory to 10k+ varieties: - Render the list with ListView.builder over a flattened header/item model instead of building every tile upfront. - Store a small regenerable JPEG thumbnail per photo (schema v14) and use it for the 48px list avatar; full bytes stay for offer image hosting. Existing photos are backfilled lazily at startup. Thumbnail is local-only (excluded from CRDT sync and backups by the JSON codec). - Add indexes on varieties(is_deleted,is_draft), attachments(parent_type, parent_id,kind), lots(variety_id) via @TableIndex. - Debounce watchInventoryView (~250ms) so a burst of table writes triggers one reload, not seven. - cacheWidth/cacheHeight on the list avatar decode. - Scale test raised 3k -> 10k; migration test v13 -> v14.
This commit is contained in:
parent
2884ddd3c7
commit
3de01bd948
12 changed files with 5114 additions and 34 deletions
|
|
@ -19,8 +19,8 @@ void main() {
|
|||
});
|
||||
tearDown(() => db.close());
|
||||
|
||||
test('the inventory view loads 3000 varieties quickly', () async {
|
||||
const count = 3000;
|
||||
test('the inventory view loads 10000 varieties quickly', () async {
|
||||
const count = 10000;
|
||||
for (var i = 0; i < count; i++) {
|
||||
final id = await repo.addQuickVariety(
|
||||
label: 'Variety $i',
|
||||
|
|
@ -43,11 +43,12 @@ void main() {
|
|||
sw.stop();
|
||||
|
||||
expect(view.items, hasLength(count));
|
||||
// Generous ceiling for CI; typical local runs are well under 500ms. The
|
||||
// point is to catch an accidental N+1 regression, not to micro-benchmark.
|
||||
// Generous ceiling for CI (the point is to catch an N+1 regression, not to
|
||||
// micro-benchmark). Includes the ~250ms debounce on the first emit; typical
|
||||
// local runs are well under 2s for 10k rows with the v14 indexes.
|
||||
expect(
|
||||
sw.elapsedMilliseconds,
|
||||
lessThan(3000),
|
||||
lessThan(6000),
|
||||
reason: 'inventory view took ${sw.elapsedMilliseconds}ms for $count rows',
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,19 +11,19 @@ void main() {
|
|||
verifier = SchemaVerifier(GeneratedHelper());
|
||||
});
|
||||
|
||||
test('freshly created database matches the exported schema v13', () async {
|
||||
final schema = await verifier.schemaAt(13);
|
||||
test('freshly created database matches the exported schema v14', () async {
|
||||
final schema = await verifier.schemaAt(14);
|
||||
final db = AppDatabase(schema.newConnection());
|
||||
await verifier.migrateAndValidate(db, 13);
|
||||
await verifier.migrateAndValidate(db, 14);
|
||||
await db.close();
|
||||
});
|
||||
|
||||
// Every historical version upgrades cleanly to the current schema (v13).
|
||||
for (var from = 1; from <= 12; from++) {
|
||||
test('upgrades v$from → v13 and matches the fresh schema', () async {
|
||||
// Every historical version upgrades cleanly to the current schema (v14).
|
||||
for (var from = 1; from <= 13; from++) {
|
||||
test('upgrades v$from → v14 and matches the fresh schema', () async {
|
||||
final connection = await verifier.startAt(from);
|
||||
final db = AppDatabase(connection);
|
||||
await verifier.migrateAndValidate(db, 13);
|
||||
await verifier.migrateAndValidate(db, 14);
|
||||
await db.close();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import 'schema_v10.dart' as v10;
|
|||
import 'schema_v11.dart' as v11;
|
||||
import 'schema_v12.dart' as v12;
|
||||
import 'schema_v13.dart' as v13;
|
||||
import 'schema_v14.dart' as v14;
|
||||
|
||||
class GeneratedHelper implements SchemaInstantiationHelper {
|
||||
@override
|
||||
|
|
@ -48,10 +49,12 @@ class GeneratedHelper implements SchemaInstantiationHelper {
|
|||
return v12.DatabaseAtV12(db);
|
||||
case 13:
|
||||
return v13.DatabaseAtV13(db);
|
||||
case 14:
|
||||
return v14.DatabaseAtV14(db);
|
||||
default:
|
||||
throw MissingSchemaException(version, versions);
|
||||
}
|
||||
}
|
||||
|
||||
static const versions = const [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
|
||||
static const versions = const [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
|
||||
}
|
||||
|
|
|
|||
2248
apps/app_seeds/test/db/schema/schema_v14.dart
Normal file
2248
apps/app_seeds/test/db/schema/schema_v14.dart
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue