Skip to content
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

fix: Reduce redundant network calls in rill developer #4883

Merged
merged 9 commits into from
May 23, 2024

Conversation

AdityaHegde
Copy link
Collaborator

@AdityaHegde AdityaHegde commented May 13, 2024

We have multiple redundant network calls in rill developer.

  • During initial load we make a call to all resource and all files names. Separately we also make a call to all resources, this can be filled in using all resources call.
  • WatchResourceClient receives the updated resource, but we still make another call to it.
  • We refresh list of all file names for every file write. We can only do this when a new file is added or file is deleted.
  • We make a call to ListResources with kind in addition to the ListResource with no params. We can filter from the full list instead. (Dashboard list is pending since it used in cloud where we might not always make a call to list resources)

This also attempts to move any metadata needed for these watch clients to those files instead of the global store FileArtifacts.

  • Add WatchFileClient to store any metadata needed only during watching files.
  • Add WatchResourceClient to store metadata needed only during watching resources.
  • Finally fix E2E and make sure there are no regressions.

@AdityaHegde AdityaHegde marked this pull request as draft May 13, 2024 10:17
@ericpgreen2
Copy link
Contributor

/review

@rill-dev
Copy link
Collaborator

rill-dev commented May 14, 2024

Code Review Agent Run Status

  • AI Based Review: Successful

Code Review Overview

  • Summary: The PR introduces significant optimizations and refactoring aimed at reducing redundant network calls in the Rill Developer environment. Changes include the introduction of new utility classes for resource management, optimization of resource and file metadata handling, and removal of outdated methods and properties.
  • Code change type: Optimisation, Refactoring
  • Unit tests added: True
  • Estimated effort to review (1-5, lower is better): 3

>>See detailed code suggestions<<
The Bito AI Code Review Agent successfully reviewed 16 files and discovered 4 issues. Please review these issues along with suggested fixes in the Changed Files.

See other commands you can run

High-level Feedback

Ensure consistent use of resource management methods across all components to maintain efficiency. Review the changes for potential impacts on existing functionalities and compatibility with cloud environments. Consider adding more comprehensive tests to cover new changes and ensure that private constructors do not hinder unit testing.

});
}

public async waitForResource(name: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Issue: The method 'waitForResource' uses a hard-coded comparison string "RECONCILE_STATUS_IDLE", which could limit the flexibility of the ResourceWatcher class.
Fix: Consider making the status string a parameter of the 'waitForResource' method or part of the class configuration to increase flexibility and reusability of the 'ResourceWatcher' class.
Code Suggestion:

- return waitUntil(() => this.statuses.get(name) === "RECONCILE_STATUS_IDLE");
+ return waitUntil(() => this.statuses.get(name) === this.idleStatus); // this.idleStatus should be configurable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It doesnt make sense to make this configurable.

@@ -1,13 +1,13 @@
<script lang="ts">
import { fileArtifacts } from "@rilldata/web-common/features/entity-management/file-artifacts";
import { createWatchFilesClient } from "@rilldata/web-common/features/entity-management/watch-files-client";
import { createWatchResourceClient } from "@rilldata/web-common/features/entity-management/watch-resources-client";
import { WatchFilesClient } from "@rilldata/web-common/features/entity-management/WatchFilesClient";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Issue: Import statements for 'WatchFilesClient' and 'WatchResourcesClient' use incorrect paths or naming conventions.
Fix: Correct the import statements to match the actual file names and paths in the project structure.
Code Suggestion:

-  import { WatchFilesClient } from "@rilldata/web-common/features/entity-management/WatchFilesClient";
-  import { WatchResourcesClient } from "@rilldata/web-common/features/entity-management/WatchResourcesClient";
+  import { WatchFilesClient } from "@rilldata/web-common/features/entity-management/watch-files-client";
+  import { WatchResourcesClient } from "@rilldata/web-common/features/entity-management/watch-resources-client";

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This seems to be incorrect, did it not catch the file name rename? The file name should match the class name with camel case.

@rilldata rilldata deleted a comment from rill-dev May 14, 2024
Copy link
Contributor

@ericpgreen2 ericpgreen2 left a comment

Choose a reason for hiding this comment

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

Some great cleanup in here!

Comment on lines 24 to 27
public static New() {
const watcher = new WatchFilesClient();
return watcher.client;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems unconventional in Javascript. Can we just use the constructor to instantiate a new instance?

private invalidateAllFiles() {
// TODO: reset project parser errors
const instanceId = get(runtime).instanceId;
return queryClient.resetQueries({
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally we move from resetQueries to refetchQueries everywhere (but if that's risky, OK to keep out-of-scope of this PR). resetQueries typically leads to flashing.

const instanceId = get(runtime).instanceId;
const isNew = !this.seenFiles.has(res.path);

console.log(res.path, isNew);
Copy link
Contributor

Choose a reason for hiding this comment

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

Leftover console.log

Comment on lines 53 to 56
public static New() {
const watcher = new WatchResourcesClient();
return watcher.client;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, this seems unconventional in Javascript

Comment on lines 7 to 21
export function refreshResource(
queryClient: QueryClient,
instanceId: string,
res: V1Resource,
) {
return queryClient.resetQueries(
return queryClient.setQueryData(
getRuntimeServiceGetResourceQueryKey(instanceId, {
"name.name": res.meta?.name?.name,
"name.kind": res.meta?.name?.kind,
}),
{
resource: res,
},
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Given this function is just a wrapper around setQueryData, can we remove the wrapper and use setQueryData directly? Else it requires a reader to mentally map "refreshResource" -> setQueryData, which seems unnecessary.

}

public async waitForResource(name: string) {
return waitUntil(() => this.statuses.get(name) === "RECONCILE_STATUS_IDLE");
Copy link
Contributor

Choose a reason for hiding this comment

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

Our e2e tests should rely on user-visible indicators, not on internal state

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True. I am iterating on this. That part is still TODO

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually I am not sure if any user-visible indicators was reliable here. That is why we had waitForResource earlier.

* Fetches all resources and filters them client side.
* This is to improve network requests since we need the full list all the time as well.
*/
export function useClientFilteredResources(
Copy link
Contributor

Choose a reason for hiding this comment

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

Great!

return watcher.client;
}

private handleWatchResourceResponse(res: V1WatchResourcesResponse) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this code co-location!

@AdityaHegde
Copy link
Collaborator Author

Hey sorry this is not ready for review. Hence the bunch of console logs. Sorry if i gave the wrong impression. Also the AI seems wrong most of the time. It feels like spam most of the time.

@AdityaHegde AdityaHegde force-pushed the adityahegde/rill-developer-network-improvements branch from 6468a84 to 26d5cea Compare May 15, 2024 07:35
@AdityaHegde AdityaHegde marked this pull request as ready for review May 23, 2024 16:37
@rilldata rilldata deleted a comment from rill-dev May 23, 2024
@ericpgreen2 ericpgreen2 merged commit 905a798 into main May 23, 2024
4 checks passed
@ericpgreen2 ericpgreen2 deleted the adityahegde/rill-developer-network-improvements branch May 23, 2024 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants