Skip to content

Commit

Permalink
Ports: Adds Sequential mode to SQDL2 (#9846)
Browse files Browse the repository at this point in the history
* Adds sequential mode to SDQL

* Fix sequential SDQL being default (#44476)

* Fix

This is not ideal, but I have been able to find a better solution as of yet and I doubt it'll cause any issues

---------

Co-authored-by: AnturK <[email protected]>
  • Loading branch information
Tyranicranger4 and AnturK authored Sep 29, 2023
1 parent 406acd5 commit 7a553a1
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions code/modules/admin/verbs/SDQL2/SDQL_2.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -222,6 +223,7 @@
NOTICE(query_log)

var/start_time_total = REALTIMEOFDAY
var/sequential = FALSE

if(!length(query_text))
return
Expand All @@ -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, "<span class='admin'>[msg]</span>")
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, "<span class='admin'>[msg]</span>")
log_admin(msg)
query.ARun()

var/finished = FALSE
var/objs_all = 0
var/objs_eligible = 0
Expand All @@ -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, "<span class='admin'>SDQL query [query.get_query_text()] errored. It will NOT be automatically garbage collected. Please remove manually.</span>")
running -= query
if(query.state == SDQL2_STATE_ERROR)
if(usr)
to_chat(usr, "<span class='admin'>SDQL query [query.get_query_text()] errored. It will NOT be automatically garbage collected. Please remove manually.</span>")
running -= query
else
if(query.finished)
objs_all += islist(query.obj_count_all)? length(query.obj_count_all) : query.obj_count_all
Expand 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, "<span class='admin'>[msg]</span>")
log_admin(msg)
next_query.ARun()
else
if(usr)
to_chat(usr, "<span class='admin'>SDQL query [query.get_query_text()] was halted. It will NOT be automatically garbage collected. Please remove manually.</span>")
Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit 7a553a1

Please sign in to comment.