Skip to content

Conversation

aeisenberg
Copy link
Contributor

Remote query items will be stored in query history and will remain
available across restarts.

When the extension is restarted, any InProgress remote queries will
be monitored until they complete.

When clicked on, a remote query is opened and its results can be
downloaded. The query text and the query file can be opened from the
history menu. A remote query can be deleted as well, which will purge
all results from global storage.

Limitations:

  1. Labels are not editable
  2. Running multiple queries that each run on the same repository
    will have conflicting results and there will be errors when trying
    to view the results of the second query. This limitation is not new,
    but it is easier to hit now. See Download and process analyses results #1089.

Both of these limitations will be addressed in future PRs.

Checklist

  • [n/a] CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [n/a] [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

@aeisenberg aeisenberg requested review from a team as code owners February 22, 2022 18:44
@aeisenberg aeisenberg force-pushed the aeisenberg/remote-query-restart branch from 579d210 to cf0728a Compare February 22, 2022 19:37
Remote query items will be stored in query history and will remain
available across restarts.

When the extension is restarted, any `InProgress` remote queries will
be monitored until they complete.

When clicked on, a remote query is opened and its results can be
downloaded. The query text and the query file can be opened from the
history menu. A remote query can be deleted as well, which will purge
all results from global storage.

Limitations:

1. Labels are not editable
2. Running multiple queries that each run on the same repository
   will have conflicting results and there will be errors when trying
   to view the results of the second query. This limitation is not new,
   but it is easier to hit now. See #1089.

Both of these limitations will be addressed in future PRs.
@aeisenberg aeisenberg force-pushed the aeisenberg/remote-query-restart branch from cf0728a to 5e06a61 Compare February 22, 2022 19:43
Copy link
Contributor

@charisk charisk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the hard work on this, I'm starting to see the light at the end of the tunnel!

private async handleOpenQueryItem(queryItem: QueryHistoryInfo) {
if (queryItem?.t === 'remote') {
try {
const remoteQueryResult = await this.retrieveJsonFile(queryItem, 'query-result.json') as RemoteQueryResult;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to have this instead?

Suggested change
const remoteQueryResult = await this.retrieveJsonFile(queryItem, 'query-result.json') as RemoteQueryResult;
const remoteQueryResult = await this.retrieveJsonFile<RemoteQueryResult>(queryItem, 'query-result.json');

this.push(this.qhm.onWillOpenQueryItem(this.handleOpenQueryItem.bind(this)));
}

private async handleAddQueryItem(queryItem: QueryHistoryInfo) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A convention I've been following that I'd love to see (and we can discuss about whether we agree/want to enforce it with a linter) is to have public functions before private functions. I find that easier when I'm reading through code because I can easily see the public interface of a module.

I'd be great if we could do the same with these functions, but ignore me if you disagree/would cause too much merge pain.

};
}

public async openResults(query: RemoteQuery, queryResult: RemoteQueryResult) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The public functions of the RemoteQueriesManager are runRemoteQuery, monitorRemoteQuery, etc. so perhaps a better name for this function would be openRemoteQuery or showRemoteQuery.

await fs.writeFile(filePath, JSON.stringify(obj, null, 2), 'utf8');
}

private async retrieveJsonFile<T>(queryHistoryItem: RemoteQueryHistoryItem, fileName: string): Promise<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is retrieveQueryJson a better name for this?

export class RemoteQueryHistoryItem {
readonly t = 'remote';
failureReason: string | undefined;
export interface RemoteQueryHistoryItem {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay! Very happy to see this being turned back into a plain interface!

this.remoteQueriesMonitor = new RemoteQueriesMonitor(ctx, logger);

// Handle events from the query history manager
this.push(this.qhm.onDidAddQueryItem(this.handleAddQueryItem.bind(this)));
Copy link
Contributor

@charisk charisk Feb 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 There is a level of indirection that I feel we should be able to simplify: we have a logical circular dependency between the two managers (RemoteQueryManager and QueryHistoryManager) because the two need to work together - the responsibilities get a bit blurred. For example, handleAddQueryItem will be called for non remote queries so we have to check that. It'd be great if there was better isolation there (i.e. never call that for non remote queries).

What you have here works 🎉 so in the sake of speed, I think we should go ahead with what we've got, but I have some ideas about how we could simplify this and make it a bit more readable/maintainable

Base automatically changed from aeisenberg/remote-query-save to main February 23, 2022 19:13
@aeisenberg aeisenberg merged commit 06de607 into main Feb 23, 2022
@aeisenberg aeisenberg deleted the aeisenberg/remote-query-restart branch February 23, 2022 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants