aboutsummaryrefslogtreecommitdiff
path: root/ui/src/controller/query_controller.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/controller/query_controller.ts')
-rw-r--r--ui/src/controller/query_controller.ts46
1 files changed, 9 insertions, 37 deletions
diff --git a/ui/src/controller/query_controller.ts b/ui/src/controller/query_controller.ts
index c4bd9d485..b551a11ac 100644
--- a/ui/src/controller/query_controller.ts
+++ b/ui/src/controller/query_controller.ts
@@ -15,9 +15,8 @@
import {assertExists} from '../base/logging';
import {Actions} from '../common/actions';
import {Engine} from '../common/engine';
-import {rawQueryResultColumns, rawQueryResultIter, Row} from '../common/protos';
-import {QueryResponse} from '../common/queries';
-import {slowlyCountRows} from '../common/query_iterator';
+import {runQuery} from '../common/queries';
+import {publishQueryResult} from '../frontend/publish';
import {Controller} from './controller';
import {globals} from './globals';
@@ -36,11 +35,13 @@ export class QueryController extends Controller<'init'|'querying'> {
switch (this.state) {
case 'init':
const config = assertExists(globals.state.queries[this.args.queryId]);
- this.runQuery(config.query).then(result => {
- console.log(`Query ${config.query} took ${result.durationMs} ms`);
- globals.publish('QueryResult', {id: this.args.queryId, data: result});
- globals.dispatch(Actions.deleteQuery({queryId: this.args.queryId}));
- });
+ runQuery(this.args.queryId, config.query, this.args.engine)
+ .then(result => {
+ console.log(`Query ${config.query} took ${result.durationMs} ms`);
+ publishQueryResult({id: this.args.queryId, data: result});
+ globals.dispatch(
+ Actions.deleteQuery({queryId: this.args.queryId}));
+ });
this.setState('querying');
break;
@@ -53,33 +54,4 @@ export class QueryController extends Controller<'init'|'querying'> {
throw new Error(`Unexpected state ${this.state}`);
}
}
-
- private async runQuery(sqlQuery: string) {
- const startMs = performance.now();
- const rawResult = await this.args.engine.uncheckedQuery(sqlQuery);
- const durationMs = performance.now() - startMs;
- const columns = rawQueryResultColumns(rawResult);
- const rows =
- QueryController.firstN<Row>(10000, rawQueryResultIter(rawResult));
- const result: QueryResponse = {
- id: this.args.queryId,
- query: sqlQuery,
- durationMs,
- error: rawResult.error,
- totalRowCount: slowlyCountRows(rawResult),
- columns,
- rows,
- };
- return result;
- }
-
- private static firstN<T>(n: number, iter: IterableIterator<T>): T[] {
- const list = [];
- for (let i = 0; i < n; i++) {
- const {done, value} = iter.next();
- if (done) break;
- list.push(value);
- }
- return list;
- }
}