From 8972c52ca1769b45f3b273fac25dfba2df57244e Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Mon, 6 Jun 2022 13:31:31 +0200 Subject: [PATCH] [MIRROR] Adminwho now caches feedback links until admins are reloaded (and also works again) [MDB IGNORE] (#14135) * Adminwho now caches feedback links until admins are reloaded (and also works again) (#67307) * Adminwho now caches feedback links until admins are reloaded * Restore dbconfig * Fix feedback links, make them query only if necessary, and not on load admins * Wait longer before checking DB connection * Back on my dbconfig shit fixes (Adminwho is slower than it needs to be after feedback links) #67150. also fixes (timber breaking feedback links totally by qdeling the datum too early) #67360. * Adminwho now caches feedback links until admins are reloaded (and also works again) Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com> --- code/__DEFINES/admin.dm | 3 +++ code/modules/admin/admin_ranks.dm | 6 ++++-- code/modules/admin/holder2.dm | 23 ++++++++++++++--------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/code/__DEFINES/admin.dm b/code/__DEFINES/admin.dm index 2d676cb55fc..e67a1596793 100644 --- a/code/__DEFINES/admin.dm +++ b/code/__DEFINES/admin.dm @@ -151,3 +151,6 @@ GLOBAL_VAR_INIT(ghost_role_flags, (~0)) /// When passed in as the duration for ban_panel, will make the ban default to permanent #define BAN_PANEL_PERMANENT "permanent" + +/// A value for /datum/admins/cached_feedback_link to indicate empty, rather than unobtained +#define NO_FEEDBACK_LINK "no_feedback_link" diff --git a/code/modules/admin/admin_ranks.dm b/code/modules/admin/admin_ranks.dm index ab9417f2d6d..baa8a291974 100644 --- a/code/modules/admin/admin_ranks.dm +++ b/code/modules/admin/admin_ranks.dm @@ -258,7 +258,7 @@ GLOBAL_PROTECT(protected_ranks) new /datum/admins(ranks_from_rank_name(admin_rank), ckey(admin_key), force_active = FALSE, protected = TRUE) if(!CONFIG_GET(flag/admin_legacy_system) || dbfail) - var/datum/db_query/query_load_admins = SSdbcore.NewQuery("SELECT ckey, `rank` FROM [format_table_name("admin")] ORDER BY `rank`") + var/datum/db_query/query_load_admins = SSdbcore.NewQuery("SELECT ckey, `rank`, feedback FROM [format_table_name("admin")] ORDER BY `rank`") if(!query_load_admins.Execute()) message_admins("Error loading admins from database. Loading from backup.") log_sql("Error loading admins from database. Loading from backup.") @@ -267,6 +267,7 @@ GLOBAL_PROTECT(protected_ranks) while(query_load_admins.NextRow()) var/admin_ckey = ckey(query_load_admins.item[1]) var/admin_rank = query_load_admins.item[2] + var/admin_feedback = query_load_admins.item[3] var/skip var/list/admin_ranks = ranks_from_rank_name(admin_rank) @@ -277,7 +278,8 @@ GLOBAL_PROTECT(protected_ranks) if(GLOB.admin_datums[admin_ckey] || GLOB.deadmins[admin_ckey]) skip = 1 if(!skip) - new /datum/admins(admin_ranks, admin_ckey) + var/datum/admins/admin_holder = new(admin_ranks, admin_ckey) + admin_holder.cached_feedback_link = admin_feedback || NO_FEEDBACK_LINK qdel(query_load_admins) //load admins from backup file if(dbfail) diff --git a/code/modules/admin/holder2.dm b/code/modules/admin/holder2.dm index ff780c582be..7ea622db3a9 100644 --- a/code/modules/admin/holder2.dm +++ b/code/modules/admin/holder2.dm @@ -30,9 +30,7 @@ GLOBAL_PROTECT(href_token) var/href_token /// Link from the database pointing to the admin's feedback forum - var/cached_forum_link - /// Last access time in deciseconds (playing nice with the MSO 10 second rule) - var/last_forum_access_time + var/cached_feedback_link var/deadmined @@ -172,25 +170,32 @@ GLOBAL_PROTECT(href_token) /// Returns the feedback forum thread for the admin holder's owner, as according to DB. /datum/admins/proc/feedback_link() - if(world.time - last_forum_access_time <= 10 SECONDS) - return cached_forum_link + // This intentionally does not follow the 10-second maximum TTL rule, + // as this can be reloaded through the Reload-Admins verb. + if (cached_feedback_link == NO_FEEDBACK_LINK) + return null - last_forum_access_time = world.time + if (!isnull(cached_feedback_link)) + return cached_feedback_link + + if (!SSdbcore.IsConnected()) + return FALSE var/datum/db_query/feedback_query = SSdbcore.NewQuery("SELECT feedback FROM [format_table_name("admin")] WHERE ckey = '[owner.ckey]'") if(!feedback_query.Execute()) log_sql("Error retrieving feedback link for [src]") qdel(feedback_query) - return cached_forum_link + return FALSE + if(!feedback_query.NextRow()) qdel(feedback_query) return FALSE // no feedback link exists + cached_feedback_link = feedback_query.item[1] || NO_FEEDBACK_LINK qdel(feedback_query) - cached_forum_link = feedback_query.item[1] - return cached_forum_link + return cached_feedback_link /datum/admins/proc/check_for_rights(rights_required) if(rights_required && !(rights_required & rank_flags()))