Qdels queries, adds sleep safety checks, DBcore checks for leaks (#38363)

* Qdels all queries, adds sleep handling

* DB Core messages admins about undeleted queries

* Compile fixes. Adds missing set waitfor

* Remove world/New shennanigans. Add DBQuery/BlockingExecute()

* Less spammy notifications to admins about undeleted queries

* Increase dbcore fire time to 1 minute

* Upgrade undeleted query warning

* Better place of death

* Fix build

* Remove BlockingExecute, see BSQL PR for why

* Yep, missed that one.

* Psyche, that's the WRONG QUERY!!
This commit is contained in:
Jordan Brown
2018-06-18 15:48:35 -04:00
committed by vuonojenmustaturska
parent 7b2fb71c1d
commit cf7e8aa9ec
41 changed files with 517 additions and 139 deletions
+28 -14
View File
@@ -41,6 +41,8 @@
if(1)
if (!SSdbcore.Connect())
dat += "<font color=red><b>ERROR</b>: Unable to contact External Archive. Please contact your system administrator for assistance.</font><BR>"
else if(QDELETED(user))
return
else if(!SQLquery)
dat += "<font color=red><b>ERROR</b>: Malformed search request. Please contact your system administrator for assistance.</font><BR>"
else
@@ -50,12 +52,16 @@
var/datum/DBQuery/query_library_list_books = SSdbcore.NewQuery(SQLquery)
if(!query_library_list_books.Execute())
dat += "<font color=red><b>ERROR</b>: Unable to retrieve book listings. Please contact your system administrator for assistance.</font><BR>"
while(query_library_list_books.NextRow())
var/author = query_library_list_books.item[1]
var/title = query_library_list_books.item[2]
var/category = query_library_list_books.item[3]
var/id = query_library_list_books.item[4]
dat += "<tr><td>[author]</td><td>[title]</td><td>[category]</td><td>[id]</td></tr>"
else
while(query_library_list_books.NextRow())
var/author = query_library_list_books.item[1]
var/title = query_library_list_books.item[2]
var/category = query_library_list_books.item[3]
var/id = query_library_list_books.item[4]
dat += "<tr><td>[author]</td><td>[title]</td><td>[category]</td><td>[id]</td></tr>"
qdel(query_library_list_books)
if(QDELETED(user))
return
dat += "</table><BR>"
dat += "<A href='?src=[REF(src)];back=1'>\[Go Back\]</A><BR>"
var/datum/browser/popup = new(user, "publiclibrary", name, 600, 400)
@@ -135,6 +141,7 @@ GLOBAL_LIST(cachedbooks) // List of our cached book datums
GLOB.cachedbooks = list()
var/datum/DBQuery/query_library_cache = SSdbcore.NewQuery("SELECT id, author, title, category FROM [format_table_name("library")] WHERE isnull(deleted)")
if(!query_library_cache.Execute())
qdel(query_library_cache)
return
while(query_library_cache.NextRow())
var/datum/cachedbook/newbook = new()
@@ -143,6 +150,7 @@ GLOBAL_LIST(cachedbooks) // List of our cached book datums
newbook.title = query_library_cache.item[3]
newbook.category = query_library_cache.item[4]
GLOB.cachedbooks += newbook
qdel(query_library_cache)
@@ -414,12 +422,15 @@ GLOBAL_LIST(cachedbooks) // List of our cached book datums
var/sqlauthor = sanitizeSQL(scanner.cache.author)
var/sqlcontent = sanitizeSQL(scanner.cache.dat)
var/sqlcategory = sanitizeSQL(upload_category)
var/msg = "[key_name(usr)] has uploaded the book titled [scanner.cache.name], [length(scanner.cache.dat)] signs"
var/datum/DBQuery/query_library_upload = SSdbcore.NewQuery("INSERT INTO [format_table_name("library")] (author, title, content, category, ckey, datetime, round_id_created) VALUES ('[sqlauthor]', '[sqltitle]', '[sqlcontent]', '[sqlcategory]', '[usr.ckey]', Now(), '[GLOB.round_id]')")
if(!query_library_upload.Execute())
qdel(query_library_upload)
alert("Database error encountered uploading to Archive")
return
else
log_game("[key_name(usr)] has uploaded the book titled [scanner.cache.name], [length(scanner.cache.dat)] signs")
log_game(msg)
qdel(query_library_upload)
alert("Upload Complete. Uploaded title will be unavailable for printing for a short period")
if(href_list["newspost"])
if(!GLOB.news_network)
@@ -452,20 +463,23 @@ GLOBAL_LIST(cachedbooks) // List of our cached book datums
cooldown = world.time + PRINTER_COOLDOWN
var/datum/DBQuery/query_library_print = SSdbcore.NewQuery("SELECT * FROM [format_table_name("library")] WHERE id=[sqlid] AND isnull(deleted)")
if(!query_library_print.Execute())
qdel(query_library_print)
say("PRINTER ERROR! Failed to print document (0x0000000F)")
return
while(query_library_print.NextRow())
var/author = query_library_print.item[2]
var/title = query_library_print.item[3]
var/content = query_library_print.item[4]
var/obj/item/book/B = new(get_turf(src))
B.name = "Book: [title]"
B.title = title
B.author = author
B.dat = content
B.icon_state = "book[rand(1,8)]"
visible_message("[src]'s printer hums as it produces a completely bound book. How did it do that?")
if(!QDELETED(src))
var/obj/item/book/B = new(get_turf(src))
B.name = "Book: [title]"
B.title = title
B.author = author
B.dat = content
B.icon_state = "book[rand(1,8)]"
visible_message("[src]'s printer hums as it produces a completely bound book. How did it do that?")
break
qdel(query_library_print)
if(href_list["printbible"])
if(cooldown < world.time)
var/obj/item/storage/book/bible/B = new /obj/item/storage/book/bible(src.loc)
+1 -2
View File
@@ -60,8 +60,7 @@
B.dat = query_get_random_books.item[4]
B.name = "Book: [B.title]"
B.icon_state= "book[rand(1,8)]"
else
return
qdel(query_get_random_books)
/obj/structure/bookcase/random/fiction
name = "bookcase (Fiction)"