Skip to content

Commit a3e5f8f

Browse files
committed
feat(database): add indexes for country aggregation queries
- Add 'eventCountry_status_index' on 'headlines' collection - Add 'headquarters_status_index' on 'sources' collection - These indexes will improve performance for country-based analytics
1 parent acb499b commit a3e5f8f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/src/services/database_seeding_service.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ class DatabaseSeedingService {
118118
.collection('sources')
119119
.createIndex(keys: {'name': 'text'}, name: 'sources_text_index');
120120

121+
// Indexes for country aggregation queries
122+
await _db.collection('headlines').createIndex(
123+
keys: {'eventCountry.id': 1, 'status': 1},
124+
name: 'eventCountry_status_index',
125+
);
126+
await _db.collection('sources').createIndex(
127+
keys: {'headquarters.id': 1, 'status': 1},
128+
name: 'headquarters_status_index',
129+
);
130+
121131
// --- TTL and Unique Indexes via runCommand ---
122132
// The following indexes are created using the generic `runCommand` because
123133
// they require specific options not exposed by the simpler `createIndex`

0 commit comments

Comments
 (0)