Bug Fixes:

- Remove outdated timetable data,
 - Ensure a 'Delete' transaction only deletes required data
 - Bump version to 2023.6.6
This commit is contained in:
Fred Boniface 2023-06-05 20:55:59 +01:00
parent e52ec43939
commit 2ca5a86030
2 changed files with 9 additions and 6 deletions

View File

@ -14,7 +14,7 @@
# program. If not, see
# https://git.fjla.uk/OwlBoard/db-manager/src/branch/main/LICENSE
version = "2023.6.5"
version = "2023.6.6"
print(f"main.py: Initialising db-manager v{version}")
#Third Party Imports

View File

@ -141,6 +141,7 @@ def insertSchedule(sch_record):
return document
def _insertToDb(data :list, type :str):
pre_count = mongo.getLength("timetable")
try:
if type == "full":
mongo.dropCollection("timetable")
@ -152,7 +153,9 @@ def _insertToDb(data :list, type :str):
singleList = [item]
mongo.putTimetable(singleList)
elif item['transactionType'] == "Delete":
mongo.deleteTimetableData({'trainUid': item['trainUid']}) ## Also need to consider the STP indicator and end date here else I am deleting LTP services when an STP is meant to be deleted.
mongo.deleteTimetableData({'trainUid': item['trainUid'], 'scheduleStartDate': item['scheduleStartDate'], 'stpIndicator': item['stpIndicator']}) ## Also need to consider the STP indicator and end date here else I am deleting LTP services when an STP is meant to be deleted.
post_count = mongo.getLength("timetable")
log.out(f"timetable._insertToDb: Document count difference after processing: {pre_count - post_count}", "DBUG")
return True #If Successfuls
except Exception as e:
log.out("timetable._insertToDb: Error inserting timetable data", "ERR")
@ -201,12 +204,12 @@ def _helpParseDate(string :str, time :str = "false"):
def _removeOutdatedServices():
log.out("timetable._removeOutdatedServices: Removing out of date schedules", "INFO")
preCount = mongo.getLength("timetable")
pre_count = mongo.getLength("timetable")
query = {
"schedule_end_date": {
"$lte": datetime.now()
}
}
## Important to actually call delete here!!!!
postCount = mongo.getLength("timetable")
log.out(f"timetable._removeOutdatedServices: Removed {preCount - postCount} out of date services", "DBUG")
mongo.deleteMany("timetable", query)
post_count = mongo.getLength("timetable")
log.out(f"timetable._removeOutdatedServices: Removed {pre_count - post_count} out of date services", "DBUG")