Fixed threading issues with Spinner recent queries.

fork-5.53.8
Greyson Parrelli 2022-04-01 11:56:00 -04:00 zatwierdzone przez Cody Henthorne
rodzic 593334456a
commit 0d61b8db38
2 zmienionych plików z 11 dodań i 7 usunięć

Wyświetl plik

@ -5,12 +5,12 @@
{{> partials/prefix isQuery=true}}
<!-- Query Input -->
<form action="query" method="post">
<form action="query" method="post" id="query-form">
<textarea name="query" class="query-input" placeholder="Enter your query...">{{query}}</textarea>
<input type="hidden" name="db" value="{{database}}" />
<input type="submit" name="action" value="run" onclick="onQuerySubmitted()" />
<input type="submit" name="action" value="run" />
or
<input type="submit" name="action" value="analyze" onclick="onQuerySubmitted()" />
<input type="submit" name="action" value="analyze" />
or
<button onclick="onFormatClicked(event)">format</button>
</form>
@ -57,6 +57,7 @@
function submitOnEnter(event){
if (event.which === 13 && event.shiftKey) {
event.target.form.submit();
onQuerySubmitted();
event.preventDefault();
}
}
@ -99,7 +100,8 @@
return JSON.parse(historyRaw);
}
document.querySelector('.query-input').addEventListener("keypress", submitOnEnter);
document.querySelector('.query-input').addEventListener('keypress', submitOnEnter);
document.getElementById('query-form').addEventListener('submit', onQuerySubmitted, false);
renderQueryHistory();
</script>

Wyświetl plik

@ -14,6 +14,8 @@ import java.lang.IllegalArgumentException
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import java.util.Queue
import java.util.concurrent.ConcurrentLinkedQueue
import kotlin.math.ceil
import kotlin.math.max
import kotlin.math.min
@ -39,7 +41,7 @@ internal class SpinnerServer(
registerHelper("neq", ConditionalHelpers.neq)
}
private val recentSql: MutableMap<String, MutableList<QueryItem>> = mutableMapOf()
private val recentSql: MutableMap<String, Queue<QueryItem>> = mutableMapOf()
private val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS zzz", Locale.US)
override fun serve(session: IHTTPSession): Response {
@ -70,11 +72,11 @@ internal class SpinnerServer(
}
fun onSql(dbName: String, sql: String) {
val commands: MutableList<QueryItem> = recentSql[dbName] ?: mutableListOf()
val commands: Queue<QueryItem> = recentSql[dbName] ?: ConcurrentLinkedQueue()
commands += QueryItem(System.currentTimeMillis(), sql)
if (commands.size > 100) {
commands.removeAt(0)
commands.remove()
}
recentSql[dbName] = commands