From 235f4fb60f38e28e66f0e3dad77c7f4d9a9a8c31 Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Fri, 18 Apr 2025 22:41:04 +0200 Subject: [PATCH] Refactor database queries and handle non-429 errors in history Updated database query code to use consistent parameter naming and revised query structure for clarity. Added logic in the history component to return existing data when encountering non-429 HTTP errors. --- .../database/litebans/NameHistoryMapper.java | 26 +++++++++---------- .../src/app/bans/history/history.component.ts | 3 +++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/database/src/main/java/com/alttd/altitudeweb/database/litebans/NameHistoryMapper.java b/database/src/main/java/com/alttd/altitudeweb/database/litebans/NameHistoryMapper.java index 8e3f471..ef2197f 100644 --- a/database/src/main/java/com/alttd/altitudeweb/database/litebans/NameHistoryMapper.java +++ b/database/src/main/java/com/alttd/altitudeweb/database/litebans/NameHistoryMapper.java @@ -137,20 +137,21 @@ public interface NameHistoryMapper { @Select(""" SELECT punishment.uuid, user_lookup.name AS punished_name, - reason, - banned_by_uuid, - banned_by_name, - removed_by_name, - time, - until, - removed_by_reason - FROM ${tableName} AS punishment - INNER JOIN user_lookup ON user_lookup.uuid = punishment.uuid + punishment.reason, + punishment.banned_by_uuid, + punishment.banned_by_name, + punishment.removed_by_name, + punishment.time, + punishment.until, + punishment.removed_by_reason + FROM ${table_name} AS punishment + INNER JOIN user_lookup + ON user_lookup.uuid = punishment.uuid WHERE ${name_column} LIKE #{partialName} ORDER BY time DESC LIMIT #{limit} OFFSET #{offset} """) - List getRecentHistoryForName(@Param("tableName") String tableName, + List getRecentHistoryForName(@Param("table_name") String tableName, @Param("partialName") String partialName, @Param("name_column") String nameColumn, @Param("limit") int limit, @@ -199,14 +200,13 @@ public interface NameHistoryMapper { time, until, removed_by_reason - FROM ${tableName} AS punishment - WHERE ${name_column} LIKE #{partialName} + FROM ${table_name} AS punishment ORDER BY time DESC LIMIT #{limit} OFFSET #{offset} ) AS punishment INNER JOIN user_lookup ON user_lookup.uuid = punishment.uuid """) - List getRecentHistory(@Param("tableName") String tableName, + List getRecentHistory(@Param("table_name") String tableName, @Param("limit") int limit, @Param("offset") int offset); diff --git a/frontend/src/app/bans/history/history.component.ts b/frontend/src/app/bans/history/history.component.ts index 8dcbee5..c2d6a3d 100644 --- a/frontend/src/app/bans/history/history.component.ts +++ b/frontend/src/app/bans/history/history.component.ts @@ -66,6 +66,9 @@ export class HistoryComponent implements OnInit, OnChanges { let retrySeconds = 5; if (err instanceof HttpErrorResponse) { + if (err.status !== 429) { + return this.history; + } const headers = err.headers; const retryAfterHeader = headers.get('Retry-After'); console.warn(err.error);