Command to fix #35 consequences

This commit is contained in:
dan63047 2023-10-17 00:41:45 +03:00
parent 5405b4968c
commit b7dc7d33ca
2 changed files with 38 additions and 1 deletions

View File

@ -407,12 +407,34 @@ class TetrioService extends DB {
await ensureDbIsOpen(); await ensureDbIsOpen();
final db = getDatabaseOrThrow(); final db = getDatabaseOrThrow();
for (TetraLeagueAlphaRecord match in stream.records) { for (TetraLeagueAlphaRecord match in stream.records) {
final results = await db.query(tetraLeagueMatchesTable, where: '$idCol = ?', whereArgs: [match.ownId]); final results = await db.query(tetraLeagueMatchesTable, where: '$replayID = ?', whereArgs: [match.replayId]);
if (results.isNotEmpty) continue; if (results.isNotEmpty) continue;
db.insert(tetraLeagueMatchesTable, {idCol: match.ownId, replayID: match.replayId, timestamp: match.timestamp.toString(), player1id: match.endContext.first.userId, player2id: match.endContext.last.userId, endContext1: jsonEncode(match.endContext.first.toJson()), endContext2: jsonEncode(match.endContext.last.toJson())}); db.insert(tetraLeagueMatchesTable, {idCol: match.ownId, replayID: match.replayId, timestamp: match.timestamp.toString(), player1id: match.endContext.first.userId, player2id: match.endContext.last.userId, endContext1: jsonEncode(match.endContext.first.toJson()), endContext2: jsonEncode(match.endContext.last.toJson())});
} }
} }
Future<void> removeDuplicatesFromTLMatches() async{
await ensureDbIsOpen();
final db = getDatabaseOrThrow();
await db.execute("""
DELETE FROM $tetraLeagueMatchesTable
WHERE
$idCol IN (
SELECT
$idCol
FROM (
SELECT
$idCol,
ROW_NUMBER() OVER (
PARTITION BY $replayID
ORDER BY $replayID) AS row_num
FROM $tetraLeagueMatchesTable
) t
WHERE row_num > 1
);
""");
}
Future<List<TetraLeagueAlphaRecord>> getTLMatchesbyPlayerID(String playerID) async { Future<List<TetraLeagueAlphaRecord>> getTLMatchesbyPlayerID(String playerID) async {
await ensureDbIsOpen(); await ensureDbIsOpen();
final db = getDatabaseOrThrow(); final db = getDatabaseOrThrow();

View File

@ -41,6 +41,21 @@ class TrackedPlayersState extends State<TrackedPlayersView> {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(t.trackedPlayersViewTitle), title: Text(t.trackedPlayersViewTitle),
actions: [
PopupMenuButton(
icon: const Icon(Icons.settings_backup_restore),
itemBuilder: (BuildContext context) => <PopupMenuEntry>[
PopupMenuItem(
value: 1,
child: Text("Remove duplicated TL mathces"),
),
],
onSelected: (value) {
if (value == 1) {teto.removeDuplicatesFromTLMatches();
return;}
Navigator.pushNamed(context, value);
})
],
), ),
backgroundColor: Colors.black, backgroundColor: Colors.black,
body: SafeArea( body: SafeArea(