From fd04cd5ee91152a203e00e0fc5d37ee8d853370b Mon Sep 17 00:00:00 2001 From: nevimer <77420409+nevimer@users.noreply.github.com> Date: Mon, 30 Mar 2026 21:36:21 -0400 Subject: [PATCH] improve code for privacy policy by runtime loading (#5332) ## About The Pull Request changes privacy policy code to load at player connection, rather than store a list in memory ## Why It's Good For The Game We don't need to slow down server startup or use memory holding this data that persists between rounds, that is what SQL's best at ## Proof Of Testing
Screenshots/Videos
## Changelog :cl: code: privacy policy loads on connection rather than server load /:cl: --- .../controllers/subsystem/privacy_policy.dm | 38 +++++++------------ .../modules/privacy_policy/privacy_policy.dm | 8 ++-- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/modular_zubbers/code/controllers/subsystem/privacy_policy.dm b/modular_zubbers/code/controllers/subsystem/privacy_policy.dm index 46fafa8a9c0..289b9ce7135 100644 --- a/modular_zubbers/code/controllers/subsystem/privacy_policy.dm +++ b/modular_zubbers/code/controllers/subsystem/privacy_policy.dm @@ -2,43 +2,30 @@ SUBSYSTEM_DEF(privacy) name = "Privacy Policy" flags = SS_NO_FIRE - VAR_PRIVATE/list/completed_by_ckey = list() - /datum/controller/subsystem/privacy/Initialize() if(!CONFIG_GET(flag/sql_enabled)) return - load_initial_acceptances() return SS_INIT_SUCCESS -/datum/controller/subsystem/privacy/proc/load_initial_acceptances() +/datum/controller/subsystem/privacy/proc/has_accepted(ckey, policy_key) if(!SSdbcore.IsConnected()) return - - var/datum/db_query/query = SSdbcore.NewQuery("SELECT ckey, policy_key FROM [format_table_name("privacy_policy_acceptances")]") - - if(!query.Execute()) + var/datum/db_query/query = SSdbcore.NewQuery("SELECT ckey, policy_key FROM [format_table_name("privacy_policy_acceptances")] WHERE ckey = :ckey AND policy_key = :policy_key", + list( + "ckey" = ckey, + "policy_key" = policy_key) + ) + if(!query.warn_execute()) qdel(query) - return - - while(query.NextRow()) - var/ckey = query.item[1] - var/policy_key = query.item[2] - - completed_by_ckey[ckey] ||= list() - completed_by_ckey[ckey] += policy_key - + return FALSE qdel(query) - -/datum/controller/subsystem/privacy/proc/has_accepted(ckey, policy_key) - return completed_by_ckey[ckey] && (policy_key in completed_by_ckey[ckey]) + return TRUE /datum/controller/subsystem/privacy/proc/mark_accepted(ckey, policy_key) - if(has_accepted(ckey, policy_key)) + . = has_accepted(ckey, policy_key) + if(.) return - completed_by_ckey[ckey] ||= list() - completed_by_ckey[ckey] += policy_key - var/datum/db_query/query = SSdbcore.NewQuery( "INSERT IGNORE INTO [format_table_name("privacy_policy_acceptances")] (ckey, policy_key) VALUES (:ckey, :policy_key)", list( @@ -47,5 +34,6 @@ SUBSYSTEM_DEF(privacy) ) ) - query.Execute() + query.warn_execute() qdel(query) + return . diff --git a/modular_zubbers/code/modules/privacy_policy/privacy_policy.dm b/modular_zubbers/code/modules/privacy_policy/privacy_policy.dm index e495a785c83..2b710f50513 100644 --- a/modular_zubbers/code/modules/privacy_policy/privacy_policy.dm +++ b/modular_zubbers/code/modules/privacy_policy/privacy_policy.dm @@ -9,10 +9,10 @@ return GLOB.always_state /datum/privacy_policy_ui/ui_close(mob/user) - if(!SSprivacy.has_accepted(owner.ckey, CURRENT_PRIVACY_KEY)) - if(owner) - to_chat(owner, span_danger("You must accept the Privacy Policy to continue playing.")) - New(owner) + // we spawned async and this has already been checked if we reached this point, we don't need further checks + if(owner) + to_chat(owner, span_danger("You must accept the Privacy Policy to continue playing.")) + new type(owner.mob) qdel(src) /datum/privacy_policy_ui/ui_data(mob/user)