Skip to content

Commit 72160a2

Browse files
committed
Fix incorrect call to bqrs info when retrieving paginated results
When retrieving paginated results, need to make sure we are getting page offsets from the correct results file. Previously, we were incorrectly extracting page offsets from the default (unsorted) file. With this change, we ensure that we get offsets from the proper results file when there is a request for a page of results.
1 parent 456c25f commit 72160a2

1 file changed

Lines changed: 36 additions & 35 deletions

File tree

extensions/ql-vscode/src/interface.ts

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -352,40 +352,39 @@ export class InterfaceManager extends DisposableObject {
352352
});
353353
}
354354

355-
const getParsedResultSets = async (): Promise<ParsedResultSets> => {
356-
357-
const resultSetSchemas = await this.getResultSetSchemas(results);
358-
const resultSetNames = resultSetSchemas.map(schema => schema.name);
355+
// Note that the resultSetSchemas will return offsets for the default (unsorted) page,
356+
// which may not be correct. However, in this case, it doesn't matter since we only
357+
// need the first offset, which will be the same no matter which sorting we use.
358+
const resultSetSchemas = await this.getResultSetSchemas(results);
359+
const resultSetNames = resultSetSchemas.map(schema => schema.name);
359360

360-
// This may not wind up being the page we actually show, if there are interpreted results,
361-
// but speculatively send it anyway.
362-
const selectedTable = getDefaultResultSetName(resultSetNames);
363-
const schema = resultSetSchemas.find(
364-
(resultSet) => resultSet.name == selectedTable
365-
)!;
361+
const selectedTable = getDefaultResultSetName(resultSetNames);
362+
const schema = resultSetSchemas.find(
363+
(resultSet) => resultSet.name == selectedTable
364+
)!;
366365

367-
// Use sorted results path if it exists. This may happen if we are
368-
// reloading the results view after it has been sorted in the past.
369-
const resultsPath = results.sortedResultsInfo.get(selectedTable)?.resultsPath
370-
|| results.query.resultsPaths.resultsPath;
366+
// Use sorted results path if it exists. This may happen if we are
367+
// reloading the results view after it has been sorted in the past.
368+
const resultsPath = results.sortedResultsInfo.get(selectedTable)?.resultsPath
369+
|| results.query.resultsPaths.resultsPath;
371370

372-
const chunk = await this.cliServer.bqrsDecode(
373-
resultsPath,
374-
schema.name,
375-
{
376-
offset: schema.pagination?.offsets[0],
377-
pageSize: RAW_RESULTS_PAGE_SIZE
378-
}
379-
);
380-
const resultSet = transformBqrsResultSet(schema, chunk);
381-
return {
382-
pageNumber: 0,
383-
numPages: numPagesOfResultSet(resultSet),
384-
numInterpretedPages: numInterpretedPages(this._interpretation),
385-
resultSet: { t: 'RawResultSet', ...resultSet },
386-
selectedTable: undefined,
387-
resultSetNames,
388-
};
371+
const chunk = await this.cliServer.bqrsDecode(
372+
resultsPath,
373+
schema.name,
374+
{
375+
// always use the first page. –
376+
offset: schema.pagination?.offsets[0],
377+
pageSize: RAW_RESULTS_PAGE_SIZE
378+
}
379+
);
380+
const resultSet = transformBqrsResultSet(schema, chunk);
381+
const parsedResultSets: ParsedResultSets = {
382+
pageNumber: 0,
383+
numPages: numPagesOfResultSet(resultSet),
384+
numInterpretedPages: numInterpretedPages(this._interpretation),
385+
resultSet: { ...resultSet, t: 'RawResultSet' },
386+
selectedTable: undefined,
387+
resultSetNames,
389388
};
390389

391390
await this.postMessage({
@@ -395,7 +394,7 @@ export class InterfaceManager extends DisposableObject {
395394
resultsPath: this.convertPathToWebviewUri(
396395
results.query.resultsPaths.resultsPath
397396
),
398-
parsedResultSets: await getParsedResultSets(),
397+
parsedResultSets,
399398
sortedResultsMap,
400399
database: results.database,
401400
shouldKeepOldResultsWhileRendering,
@@ -433,9 +432,11 @@ export class InterfaceManager extends DisposableObject {
433432
});
434433
}
435434

436-
private async getResultSetSchemas(results: CompletedQuery): Promise<ResultSetSchema[]> {
435+
private async getResultSetSchemas(results: CompletedQuery, selectedTable = ''): Promise<ResultSetSchema[]> {
436+
const resultsPath = results.sortedResultsInfo.get(selectedTable)?.resultsPath
437+
|| results.query.resultsPaths.resultsPath;
437438
const schemas = await this.cliServer.bqrsInfo(
438-
results.query.resultsPaths.resultsPath,
439+
resultsPath,
439440
RAW_RESULTS_PAGE_SIZE
440441
);
441442
return schemas['result-sets'];
@@ -460,7 +461,7 @@ export class InterfaceManager extends DisposableObject {
460461
(sortedResultsMap[k] = this.convertPathPropertiesToWebviewUris(v))
461462
);
462463

463-
const resultSetSchemas = await this.getResultSetSchemas(results);
464+
const resultSetSchemas = await this.getResultSetSchemas(results, sorted ? selectedTable : '');
464465
const resultSetNames = resultSetSchemas.map(schema => schema.name);
465466

466467
const schema = resultSetSchemas.find(

0 commit comments

Comments
 (0)