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.
This commit is contained in:
Teriuihi 2025-04-18 22:41:04 +02:00
parent 6dbb36399f
commit 235f4fb60f
2 changed files with 16 additions and 13 deletions

View File

@ -137,20 +137,21 @@ public interface NameHistoryMapper {
@Select(""" @Select("""
SELECT punishment.uuid, SELECT punishment.uuid,
user_lookup.name AS punished_name, user_lookup.name AS punished_name,
reason, punishment.reason,
banned_by_uuid, punishment.banned_by_uuid,
banned_by_name, punishment.banned_by_name,
removed_by_name, punishment.removed_by_name,
time, punishment.time,
until, punishment.until,
removed_by_reason punishment.removed_by_reason
FROM ${tableName} AS punishment FROM ${table_name} AS punishment
INNER JOIN user_lookup ON user_lookup.uuid = punishment.uuid INNER JOIN user_lookup
ON user_lookup.uuid = punishment.uuid
WHERE ${name_column} LIKE #{partialName} WHERE ${name_column} LIKE #{partialName}
ORDER BY time DESC ORDER BY time DESC
LIMIT #{limit} OFFSET #{offset} LIMIT #{limit} OFFSET #{offset}
""") """)
List<HistoryRecord> getRecentHistoryForName(@Param("tableName") String tableName, List<HistoryRecord> getRecentHistoryForName(@Param("table_name") String tableName,
@Param("partialName") String partialName, @Param("partialName") String partialName,
@Param("name_column") String nameColumn, @Param("name_column") String nameColumn,
@Param("limit") int limit, @Param("limit") int limit,
@ -199,14 +200,13 @@ public interface NameHistoryMapper {
time, time,
until, until,
removed_by_reason removed_by_reason
FROM ${tableName} AS punishment FROM ${table_name} AS punishment
WHERE ${name_column} LIKE #{partialName}
ORDER BY time DESC ORDER BY time DESC
LIMIT #{limit} OFFSET #{offset} LIMIT #{limit} OFFSET #{offset}
) AS punishment ) AS punishment
INNER JOIN user_lookup ON user_lookup.uuid = punishment.uuid INNER JOIN user_lookup ON user_lookup.uuid = punishment.uuid
""") """)
List<HistoryRecord> getRecentHistory(@Param("tableName") String tableName, List<HistoryRecord> getRecentHistory(@Param("table_name") String tableName,
@Param("limit") int limit, @Param("limit") int limit,
@Param("offset") int offset); @Param("offset") int offset);

View File

@ -66,6 +66,9 @@ export class HistoryComponent implements OnInit, OnChanges {
let retrySeconds = 5; let retrySeconds = 5;
if (err instanceof HttpErrorResponse) { if (err instanceof HttpErrorResponse) {
if (err.status !== 429) {
return this.history;
}
const headers = err.headers; const headers = err.headers;
const retryAfterHeader = headers.get('Retry-After'); const retryAfterHeader = headers.get('Retry-After');
console.warn(err.error); console.warn(err.error);