Skip to content

Commit

Permalink
Improve query preflight
Browse files Browse the repository at this point in the history
Now even a (configurable) timeout in the preflight results in warning
popup. This should catch queries producing small concordances but
with costly search (e.g. position ranges, negations, global conditions).

The configuration key is: global/preflight_query_timeout_ms
  • Loading branch information
tomachalek committed Apr 11, 2024
1 parent 85454ec commit 95d087c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions conf/config.default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<no_anonymous_access>0</no_anonymous_access>
<jwt_secret>my_secret</jwt_secret>
<enabled_websockets>0</enabled_websockets>
<preflight_query_timeout_ms>3000</preflight_query_timeout_ms>
</global>
<calc_backend>
<type>rq</type>
Expand Down
10 changes: 10 additions & 0 deletions conf/config.rng
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,16 @@
</oneOrMore>
</element>
</optional>
<optional>
<element name="preflight_query_timeout_ms">
<a:documentation>
For preflight queries, this speicifies how long KonText client-side waits
for the query. In case it is not finished in the limit, the client will
consider the query a &quot;long one&quot; and warn user accordingly.
</a:documentation>
<data type="nonNegativeInteger" />
</element>
</optional>
</interleave>
</element>
<element name="calc_backend">
Expand Down
1 change: 1 addition & 0 deletions lib/action/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ async def add_globals(self, app: Sanic, action_props: ActionProps, result: Dict[
result['issue_reporting_action'] = None
result['help_links'] = {}
result['_version'] = None
result['preflight_query_timeout_ms'] = settings.get_int('global', 'preflight_query_timeout_ms', 0)
return result

def init_menu(self, result):
Expand Down
1 change: 0 additions & 1 deletion lib/action/model/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@


import logging
import urllib.parse
from dataclasses import asdict
from functools import partial
from typing import (
Expand Down
16 changes: 14 additions & 2 deletions public/files/js/models/query/first.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

import { IFullActionControl } from 'kombo';
import { Observable, of as rxOf } from 'rxjs';
import { tap, map, concatMap, reduce } from 'rxjs/operators';
import { AjaxTimeoutError } from 'rxjs/ajax';
import { tap, map, concatMap, reduce, catchError } from 'rxjs/operators';
import { Dict, tuple, List, pipe, HTTP, Rx } from 'cnc-tskit';

import * as Kontext from '../../types/kontext';
Expand Down Expand Up @@ -1119,9 +1120,20 @@ export class FirstQueryFormModel extends QueryFormModel<FirstQueryFormModelState
),
this.createPreflightArgs(contextData, ttSelections, preflightSubc),
{
contentType: 'application/json'
contentType: 'application/json',
timeout: this.pageModel.getConf('PreflightTimeoutMs') || 0
}
).pipe(
catchError(
err => {
if (err instanceof AjaxTimeoutError) {
return rxOf({
sizeIpm: preflightSubc.threshold_ipm + 1
});
}
throw err;
}
),
map(
ans => ({
contextData,
Expand Down
1 change: 1 addition & 0 deletions templates/document.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@
__conf.TextDirectionRTL = {{ righttoleft|default(false, true)|to_json }};
__conf.InitialFreqLevel = {{ last_freq_level|default(1, true)|to_json }};
__conf.maxDispersionResolution = {{ max_dispersion_resulution|default(0, true)|to_json }};
__conf.PreflightTimeoutMs = {{ preflight_query_timeout_ms|to_json }};
__conf.manateeIsCustomCNC = {{ manatee_is_custom_cnc|to_json }};
{% endblock %}

0 comments on commit 95d087c

Please sign in to comment.