-
Notifications
You must be signed in to change notification settings - Fork 200
Add query history sorting for remote queries #1235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import * as path from 'path'; | ||
import * as fs from 'fs-extra'; | ||
import { | ||
commands, | ||
Disposable, | ||
|
@@ -28,7 +29,7 @@ import { URLSearchParams } from 'url'; | |
import { QueryServerClient } from './queryserver-client'; | ||
import { DisposableObject } from './pure/disposable-object'; | ||
import { commandRunner } from './commandRunner'; | ||
import { assertNever, ONE_HOUR_IN_MS, TWO_HOURS_IN_MS, getErrorMessage, getErrorStack } from './pure/helpers-pure'; | ||
import { assertNever, ONE_HOUR_IN_MS, TWO_HOURS_IN_MS, getErrorMessage, getErrorStack } from './pure/helpers-pure'; | ||
import { CompletedLocalQueryInfo, LocalQueryInfo as LocalQueryInfo, QueryHistoryInfo } from './query-results'; | ||
import { DatabaseManager } from './databases'; | ||
import { registerQueryHistoryScubber } from './query-history-scrubber'; | ||
|
@@ -181,38 +182,48 @@ export class HistoryTreeDataProvider extends DisposableObject { | |
): ProviderResult<QueryHistoryInfo[]> { | ||
return element ? [] : this.history.sort((h1, h2) => { | ||
|
||
// TODO remote queries are not implemented yet. | ||
if (h1.t !== 'local' && h2.t !== 'local') { | ||
return 0; | ||
} | ||
if (h1.t !== 'local') { | ||
return -1; | ||
} | ||
if (h2.t !== 'local') { | ||
return 1; | ||
} | ||
const h1Label = h1.label.toLowerCase(); | ||
const h2Label = h2.label.toLowerCase(); | ||
|
||
const resultCount1 = h1.completedQuery?.resultCount ?? -1; | ||
const resultCount2 = h2.completedQuery?.resultCount ?? -1; | ||
const h1Date = h1.t === 'local' | ||
? h1.initialInfo.start.getTime() | ||
: h1.remoteQuery?.executionStartTime; | ||
|
||
const h2Date = h2.t === 'local' | ||
? h2.initialInfo.start.getTime() | ||
: h2.remoteQuery?.executionStartTime; | ||
|
||
// result count for remote queries is not available here. | ||
const resultCount1 = h1.t === 'local' | ||
? h1.completedQuery?.resultCount ?? -1 | ||
: -1; | ||
const resultCount2 = h2.t === 'local' | ||
? h2.completedQuery?.resultCount ?? -1 | ||
: -1; | ||
|
||
switch (this.sortOrder) { | ||
case SortOrder.NameAsc: | ||
return h1.label.localeCompare(h2.label, env.language); | ||
return h1Label.localeCompare(h2Label, env.language); | ||
|
||
case SortOrder.NameDesc: | ||
return h2.label.localeCompare(h1.label, env.language); | ||
return h2Label.localeCompare(h1Label, env.language); | ||
|
||
case SortOrder.DateAsc: | ||
return h1.initialInfo.start.getTime() - h2.initialInfo.start.getTime(); | ||
return h1Date - h2Date; | ||
|
||
case SortOrder.DateDesc: | ||
return h2.initialInfo.start.getTime() - h1.initialInfo.start.getTime(); | ||
return h2Date - h1Date; | ||
|
||
case SortOrder.CountAsc: | ||
// If the result counts are equal, sort by name. | ||
return resultCount1 - resultCount2 === 0 | ||
? h1.label.localeCompare(h2.label, env.language) | ||
? h1Label.localeCompare(h2Label, env.language) | ||
: resultCount1 - resultCount2; | ||
|
||
case SortOrder.CountDesc: | ||
// If the result counts are equal, sort by name. | ||
return resultCount2 - resultCount1 === 0 | ||
? h2.label.localeCompare(h1.label, env.language) | ||
? h2Label.localeCompare(h1Label, env.language) | ||
: resultCount2 - resultCount1; | ||
default: | ||
assertNever(this.sortOrder); | ||
|
@@ -636,7 +647,7 @@ export class QueryHistoryManager extends DisposableObject { | |
if (response !== undefined) { | ||
// Interpret empty string response as 'go back to using default' | ||
finalSingleItem.initialInfo.userSpecifiedLabel = response === '' ? undefined : response; | ||
this.treeDataProvider.refresh(); | ||
await this.refreshTreeView(); | ||
} | ||
} | ||
|
||
|
@@ -727,20 +738,28 @@ export class QueryHistoryManager extends DisposableObject { | |
return; | ||
} | ||
|
||
let p: string | undefined; | ||
let externalFilePath: string | undefined; | ||
if (finalSingleItem.t === 'local') { | ||
if (finalSingleItem.completedQuery) { | ||
p = finalSingleItem.completedQuery.query.querySaveDir; | ||
externalFilePath = path.join(finalSingleItem.completedQuery.query.querySaveDir, 'timestamp'); | ||
} | ||
} else if (finalSingleItem.t === 'remote') { | ||
p = path.join(this.queryStorageDir, finalSingleItem.queryId); | ||
externalFilePath = path.join(this.queryStorageDir, finalSingleItem.queryId, 'timestamp'); | ||
} | ||
|
||
if (p) { | ||
if (externalFilePath) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably a fringe case, but is it worth also throwing a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm...unfortunately, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
if (!(await fs.pathExists(externalFilePath))) { | ||
// timestamp file is missing (manually deleted?) try selecting the parent folder. | ||
// It's less nice, but at least it will work. | ||
externalFilePath = path.dirname(externalFilePath); | ||
if (!(await fs.pathExists(externalFilePath))) { | ||
throw new Error(`Query directory does not exist: ${externalFilePath}`); | ||
} | ||
} | ||
try { | ||
await commands.executeCommand('revealFileInOS', Uri.file(p)); | ||
await commands.executeCommand('revealFileInOS', Uri.file(externalFilePath)); | ||
} catch (e) { | ||
throw new Error(`Failed to open ${p}: ${getErrorMessage(e)}`); | ||
throw new Error(`Failed to open ${externalFilePath}: ${getErrorMessage(e)}`); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of the
timestamp
file! ⏲️