Skip to content

Commit 735018f

Browse files
committed
refactor(database): improve indexing strategy for country aggregation queries
- Update index for headlines collection: change key order to prioritize 'status' - Update index for sources collection: change key order to prioritize 'status' - Rename indexes to better reflect their purpose and key order
1 parent a3e5f8f commit 735018f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/src/services/database_seeding_service.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,17 @@ class DatabaseSeedingService {
119119
.createIndex(keys: {'name': 'text'}, name: 'sources_text_index');
120120

121121
// Indexes for country aggregation queries
122-
await _db.collection('headlines').createIndex(
123-
keys: {'eventCountry.id': 1, 'status': 1},
124-
name: 'eventCountry_status_index',
122+
await _db
123+
.collection('headlines')
124+
.createIndex(
125+
keys: {'status': 1, 'eventCountry.id': 1},
126+
name: 'status_eventCountry_index',
125127
);
126-
await _db.collection('sources').createIndex(
127-
keys: {'headquarters.id': 1, 'status': 1},
128-
name: 'headquarters_status_index',
128+
await _db
129+
.collection('sources')
130+
.createIndex(
131+
keys: {'status': 1, 'headquarters.id': 1},
132+
name: 'status_headquarters_index',
129133
);
130134

131135
// --- TTL and Unique Indexes via runCommand ---

0 commit comments

Comments
 (0)