speed update, new table for cached stats

This commit is contained in:
Michael Simard
2021-08-04 16:32:17 -05:00
parent c38b621bdd
commit bc0dc93e9e
11 changed files with 485 additions and 139 deletions

View File

@@ -17,7 +17,6 @@ struct MatchController: RouteCollection {
matchRoute.delete("delete", "id",":id", use: deleteMatch)
matchRoute.post("update", "id",":id", use: updateMatch)
matchRoute.post("add", use: logMatch)
}
@@ -28,20 +27,21 @@ struct MatchController: RouteCollection {
let newMatch = try req.content.decode(Match.self)
return Match.find(id, on: req.db)
.unwrap(or: Abort(.notFound))
.flatMap {
$0.update(newMatch: newMatch)
return $0.save(on: req.db)
}
.map { .ok }
.map {
req.application.threadPool.runIfActive(eventLoop: req.eventLoop.next()) {
DBHelpers.relcalulateRecords(db: req.db) { MessagePort in}
}
return .ok
}
}
func deleteMatch(req: Request) throws -> EventLoopFuture<HTTPStatus> {
@@ -51,14 +51,36 @@ struct MatchController: RouteCollection {
return Match.find(id, on: req.db)
.unwrap(or: Abort(.notFound))
.flatMap { $0.delete(on: req.db) }
.map { .ok }
.map {
req.application.threadPool.runIfActive(eventLoop: req.eventLoop.next()) {
DBHelpers.relcalulateRecords(db: req.db) { MessagePort in}
}
return .ok
}
}
func logMatch(req: Request) throws -> EventLoopFuture<Match> {
let newMatch = try req.content.decode(Match.self)
return newMatch.save(on: req.db).map { newMatch}
return newMatch.save(on: req.db).map {
req.application.threadPool.runIfActive(eventLoop: req.eventLoop.next()) {
DBHelpers.relcalulateRecords(db: req.db) { MessagePort in}
}
return newMatch
}
}