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 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<HistoryRecord> getRecentHistoryForName(@Param("tableName") String tableName,
List<HistoryRecord> 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<HistoryRecord> getRecentHistory(@Param("tableName") String tableName,
List<HistoryRecord> getRecentHistory(@Param("table_name") String tableName,
@Param("limit") int limit,
@Param("offset") int offset);

View File

@ -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);