Improve CIF Indexes

This commit is contained in:
Fred Boniface 2024-04-23 20:10:04 +01:00
parent 652d900618
commit a2c5bd49ff
1 changed files with 3 additions and 11 deletions

View File

@ -154,6 +154,7 @@ func RemoveOutdatedServices(cutoff time.Time) (count int64, err error) {
// Creates indexes on the Timetable collection... Index suitability needs checking. // Creates indexes on the Timetable collection... Index suitability needs checking.
func CreateTimetableIndexes() error { func CreateTimetableIndexes() error {
log.Info("Creating timetable indexes")
coll := MongoClient.Database(DatabaseName).Collection(TimetableCollection) coll := MongoClient.Database(DatabaseName).Collection(TimetableCollection)
indexModels := []mongo.IndexModel{ indexModels := []mongo.IndexModel{
{ {
@ -163,22 +164,13 @@ func CreateTimetableIndexes() error {
{Key: "scheduleStartDate", Value: 1}, {Key: "scheduleStartDate", Value: 1},
}, },
Options: options.Index().SetName("delete_query"), Options: options.Index().SetName("delete_query"),
}, }, // The find by UID Query can make use of the delete_query index
{
Keys: bson.D{
{Key: "trainUid", Value: 1},
{Key: "scheduleStartDate", Value: 1},
{Key: "scheduleEndDate", Value: 1},
{Key: "daysRun", Value: 1},
},
Options: options.Index().SetName("find_by_uid"),
},
{ {
Keys: bson.D{ Keys: bson.D{
{Key: "headcode", Value: 1}, {Key: "headcode", Value: 1},
{Key: "daysRun", Value: 1},
{Key: "scheduleStartDate", Value: 1}, {Key: "scheduleStartDate", Value: 1},
{Key: "scheduleEndDate", Value: 1}, {Key: "scheduleEndDate", Value: 1},
{Key: "daysRun", Value: 1},
}, },
Options: options.Index().SetName("find_by_headcode"), Options: options.Index().SetName("find_by_headcode"),
}, },