Faster trackscan creation by only loading the latest scan
This commit is contained in:
parent
702070da66
commit
e9914e317b
|
@ -86,14 +86,13 @@ export class CreateTrackScan {
|
|||
* @returns The validated scan with it's laptime set.
|
||||
*/
|
||||
public async validateScan(scan: TrackScan): Promise<TrackScan> {
|
||||
const scans = await getConnection().getRepository(TrackScan).find({ where: { runner: scan.runner, valid: true }, relations: ["track"] });
|
||||
if (scans.length == 0) {
|
||||
const latestScan = await getConnection().getRepository(TrackScan).findOne({ where: { runner: scan.runner, valid: true }, relations: ["track"], order: { id: 'DESC' } });
|
||||
if (!latestScan) {
|
||||
scan.lapTime = 0;
|
||||
scan.valid = true;
|
||||
}
|
||||
else {
|
||||
const newestScan = scans[scans.length - 1];
|
||||
scan.lapTime = scan.timestamp - newestScan.timestamp;
|
||||
scan.lapTime = scan.timestamp - latestScan.timestamp;
|
||||
scan.valid = (scan.lapTime > scan.track.minimumLapTime);
|
||||
}
|
||||
return scan;
|
||||
|
|
Loading…
Reference in New Issue