Fixed threading issues with Spinner recent queries.
This commit is contained in:
parent
593334456a
commit
0d61b8db38
2 changed files with 11 additions and 7 deletions
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue