When games aren't ordered by date, the users ranking/points computation is wrong: new points count takes into account games played in the future.
This wasn't an issue until I migrated the database and lost the correspondence between the game's timestamp and database's sequence number...
Find below the proposed fix.
Definitions:
let archive(X)
be the list of games already processed and archived for player X.
let future(D, X)
be the subset of games in archive(X) having their date >= D.
let database
be the list of games in the database sorted by sequence number seq
seq is unrelated to date.
let lastSeq
be the last sequence number read from database.
let waitingList
be an ordered list of games sorted by date.
let ranking(PlayerArchive, OpponentArchive, Game, X)
be the updated ranking for player X after playing Game based on PlayerArchive and OpponentArchive of games.
Current code:
[x] read N entries from database
[x] increase lastSeq by N
[x] for each entry just read from database Game with Game.players = [ A, B ]
[x] add [Game, ranking(archive(A), archive(B), Game, A)] to archive(A)
[x] add [Game, ranking(archive(B), archive(A), Game, B)] to archive(B)
New code:
[x] read N entries from database
[x] increase lastSeq by N
[x] for each entry Game just read from database with Game.players = [ A, B ]
[ ] remove future(Game.date, A) from archive(A), add to waitingList.
[ ] remove future(Game.date, B) from archive(B), add to waitingList.
[x] add [Game, ranking(archive(A), archive(B), Game, A)] to archive(A)
[x] add [Game, ranking(archive(B), archive(A), Game, B)] to archive(B)
[ ] for each entry Game in waitingList with Game.players = [ A, B ]
[ ] remove Game from waitingList.
[ ] add [Game, ranking(archive(A), archive(B), Game, A)] to archive(A)
[ ] add [Game, ranking(archive(B), archive(A), Game, B)] to archive(B)
note: waitingList is ordered by date, so, even though processing of waitingList could share the same code as processing of readingList, there shouldn't be any future game to remove from archive...
When games aren't ordered by date, the users ranking/points computation is wrong: new points count takes into account games played in the future.
This wasn't an issue until I migrated the database and lost the correspondence between the game's timestamp and database's sequence number...
Find below the proposed fix.
Definitions:
Current code:
New code:
note: waitingList is ordered by date, so, even though processing of waitingList could share the same code as processing of readingList, there shouldn't be any future game to remove from archive...