Compare commits
No commits in common. "9bd6bbde2535c487482e56f591aa8fe511ef675c" and "652d900618ca2cb5a0d4aeda3bcd9b720357a0e7" have entirely different histories.
9bd6bbde25
...
652d900618
|
@ -33,14 +33,8 @@ func runCifFullDownload(cfg *helpers.Configuration) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to remove all non-vstp entries, else give up and delete collection
|
// Drop timetable collection
|
||||||
count, err := dbAccess.PurgeNonVstp()
|
dbAccess.DropCollection(dbAccess.TimetableCollection) // I should edit this to prevent removal of VSTP entries in the database.
|
||||||
if err != nil {
|
|
||||||
log.Warn("Error purging non-vstp schedules, dropping collection", zap.Error(err))
|
|
||||||
dbAccess.DropCollection(dbAccess.TimetableCollection) // I should edit this to prevent removal of VSTP entries in the database.
|
|
||||||
} else {
|
|
||||||
log.Info("Removed non-vstp services", zap.Int64("deletion count", count))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process CIF file
|
// Process CIF file
|
||||||
err = ProcessParsedCif(parsed)
|
err = ProcessParsedCif(parsed)
|
||||||
|
|
|
@ -108,19 +108,6 @@ func DeleteCifEntries(deletions []database.DeleteQuery) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clears all non-vstp services from the database. Used when a CIF full download is required.
|
|
||||||
func PurgeNonVstp() (int64, error) {
|
|
||||||
coll := MongoClient.Database(DatabaseName).Collection(TimetableCollection)
|
|
||||||
filter := bson.M{"serviceDetail.vstp": false}
|
|
||||||
|
|
||||||
result, err := coll.DeleteMany(context.Background(), filter)
|
|
||||||
if err != nil {
|
|
||||||
return result.DeletedCount, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.DeletedCount, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handles 'Create' tasks for CIF Schedule updates, accepts Service structs and batches their creation.
|
// Handles 'Create' tasks for CIF Schedule updates, accepts Service structs and batches their creation.
|
||||||
func CreateCifEntries(schedules []database.Service) error {
|
func CreateCifEntries(schedules []database.Service) error {
|
||||||
// Skip if deletions is empty
|
// Skip if deletions is empty
|
||||||
|
@ -167,7 +154,6 @@ 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{
|
||||||
{
|
{
|
||||||
|
@ -177,13 +163,22 @@ 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"),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue