diff --git a/code/modules/admin/verbs/SDQL2/SDQL_2.dm b/code/modules/admin/verbs/SDQL2/SDQL_2.dm index 49ea05729ebf6..4a64f05f3cc0a 100644 --- a/code/modules/admin/verbs/SDQL2/SDQL_2.dm +++ b/code/modules/admin/verbs/SDQL2/SDQL_2.dm @@ -158,6 +158,7 @@ SELECT = FORCE_NULLS, (D)SKIP_NULLS PRIORITY = HIGH, (D) NORMAL AUTOGC = (D) AUTOGC, KEEP_ALIVE + SEQUENTIAL = TRUE - The queries in this batch will be executed sequentially one by one not in parallel Example: USING PROCCALL = BLOCKING, SELECT = FORCE_NULLS, PRIORITY = HIGH SELECT /mob FROM world WHERE z == 1 @@ -172,8 +173,8 @@ #define SDQL2_STATE_SWITCHING 5 #define SDQL2_STATE_HALTING 6 -#define SDQL2_VALID_OPTION_TYPES list("proccall", "select", "priority", "autogc") -#define SDQL2_VALID_OPTION_VALUES list("async", "blocking", "force_nulls", "skip_nulls", "high", "normal", "keep_alive") +#define SDQL2_VALID_OPTION_TYPES list("proccall", "select", "priority", "autogc" , "sequential") +#define SDQL2_VALID_OPTION_VALUES list("async", "blocking", "force_nulls", "skip_nulls", "high", "normal", "keep_alive" , "true") #define SDQL2_OPTION_SELECT_OUTPUT_SKIP_NULLS (1<<0) #define SDQL2_OPTION_BLOCKING_CALLS (1<<1) @@ -222,6 +223,7 @@ NOTICE(query_log) var/start_time_total = REALTIMEOFDAY + var/sequential = FALSE if(!length(query_text)) return @@ -232,18 +234,36 @@ if(!length(querys)) return var/list/datum/SDQL2_query/running = list() + var/list/datum/SDQL2_query/waiting_queue = list() //Sequential queries queue. + for(var/list/query_tree in querys) var/datum/SDQL2_query/query = new /datum/SDQL2_query(query_tree) if(QDELETED(query)) continue if(usr) query.show_next_to_key = usr.ckey + waiting_queue += query + //This needs to be done before Run() is used, unlike every other query option, so we're checking it here and we're doing it differently + if(query.options && findtext(query_text, "sequential = true")) + sequential = TRUE + + if(sequential) //Start first one + var/datum/SDQL2_query/query = popleft(waiting_queue) running += query var/msg = "Starting query #[query.id] - [query.get_query_text()]." if(usr) to_chat(usr, "[msg]") log_admin(msg) query.ARun() + else //Start all + for(var/datum/SDQL2_query/query in waiting_queue) + running += query + var/msg = "Starting query #[query.id] - [query.get_query_text()]." + if(usr) + to_chat(usr, "[msg]") + log_admin(msg) + query.ARun() + var/finished = FALSE var/objs_all = 0 var/objs_eligible = 0 @@ -259,10 +279,10 @@ continue else if(query.state != SDQL2_STATE_IDLE) finished = FALSE - else if(query.state == SDQL2_STATE_ERROR) - if(usr) - to_chat(usr, "SDQL query [query.get_query_text()] errored. It will NOT be automatically garbage collected. Please remove manually.") - running -= query + if(query.state == SDQL2_STATE_ERROR) + if(usr) + to_chat(usr, "SDQL query [query.get_query_text()] errored. It will NOT be automatically garbage collected. Please remove manually.") + running -= query else if(query.finished) objs_all += islist(query.obj_count_all)? length(query.obj_count_all) : query.obj_count_all @@ -272,6 +292,15 @@ running -= query if(!CHECK_BITFIELD(query.options, SDQL2_OPTION_DO_NOT_AUTOGC)) QDEL_IN(query, 50) + if(sequential && waiting_queue.len) + finished = FALSE + var/datum/SDQL2_query/next_query = popleft(waiting_queue) + running += next_query + var/msg = "Starting query #[next_query.id] - [next_query.get_query_text()]." + if(usr) + to_chat(usr, "[msg]") + log_admin(msg) + next_query.ARun() else if(usr) to_chat(usr, "SDQL query [query.get_query_text()] was halted. It will NOT be automatically garbage collected. Please remove manually.") @@ -469,6 +498,7 @@ GLOBAL_LIST_INIT(sdql2_queries, GLOB.sdql2_queries || list()) if("keep_alive") ENABLE_BITFIELD(options, SDQL2_OPTION_DO_NOT_AUTOGC) + /datum/SDQL2_query/proc/ARun() INVOKE_ASYNC(src, PROC_REF(Run))