Skip to content

Commit

Permalink
Merge pull request #6187 from tomachalek/preflight_upd
Browse files Browse the repository at this point in the history
Preflight update
  • Loading branch information
tomachalek committed Apr 11, 2024
2 parents fa285ff + 95d087c commit e73b1c9
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 11 deletions.
1 change: 1 addition & 0 deletions conf/config.default.xml
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
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
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
Expand Up @@ -19,7 +19,6 @@


import logging
import urllib.parse
from dataclasses import asdict
from functools import partial
from typing import (
Expand Down
20 changes: 12 additions & 8 deletions public/files/js/app/navigation/index.ts
Expand Up @@ -68,12 +68,13 @@ export function parseUrlArgs(args:string):Array<[string, string]> {
*
*/
interface AjaxRequestProps {
accept:string,
contentType:string,
responseType:XMLHttpRequestResponseType,
method:string,
requestBody:string,
url:string
accept:string;
contentType:string;
responseType:XMLHttpRequestResponseType;
method:string;
requestBody:string;
url:string;
timeout:number;
}

/**
Expand Down Expand Up @@ -253,7 +254,8 @@ export class AppNavigation implements Kontext.IURLHandler, Kontext.IAjaxHandler
responseType: options.responseType,
method,
requestBody: body,
url
url,
timeout: options.timeout ? options.timeout : 0
}
}

Expand Down Expand Up @@ -282,7 +284,9 @@ export class AppNavigation implements Kontext.IURLHandler, Kontext.IAjaxHandler
responseType: callArgs.responseType,
headers: {
'Content-Type': callArgs.contentType
}
},
timeout: callArgs.timeout

}).pipe(
map<RxAjaxResponse<T>, T>(v => v.response)
);
Expand Down
16 changes: 14 additions & 2 deletions public/files/js/models/query/first.ts
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 public/files/js/types/kontext.ts
Expand Up @@ -356,6 +356,7 @@ export interface AjaxOptions {
contentType?:string;
responseType?:XMLHttpRequestResponseType;
accept?:string;
timeout?:number;
}

export type AsyncTaskStatus = 'PENDING'|'STARTED'|'SUCCESS'|'FAILURE';
Expand Down
1 change: 1 addition & 0 deletions templates/document.html
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 e73b1c9

Please sign in to comment.