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

feat: add way to get all instances of a type of model from dashboard #649

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jake-bassett
Copy link
Contributor

Description

Please include a summary of the change, motivation and context.

Testing

Please describe the tests that you ran to verify your changes. Please summarize what did you test and what needs to be tested e.g. deployed and tested helm chart locally.

Checklist:

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

Documentation

Make sure that you have documented corresponding changes in this repository or hypertrace docs repo if required.

@jake-bassett jake-bassett requested a review from a team as a code owner March 14, 2023 21:54
@jake-bassett jake-bassett changed the title feat: add way to get all instance of a type of model from dashboard feat: add way to get all instances of a type of model from dashboard Mar 14, 2023
@github-actions
Copy link

github-actions bot commented Mar 14, 2023

Test Results

    1 files    49 suites   21s ⏱️
298 tests 298 ✔️ 0 💤 0
299 runs  299 ✔️ 0 💤 0

Results for commit da87244.

♻️ This comment has been updated with latest results.

@codecov
Copy link

codecov bot commented Mar 14, 2023

Codecov Report

Merging #649 (da87244) into main (e8fbb73) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #649   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           53        53           
  Lines         1452      1462   +10     
  Branches       202       205    +3     
=========================================
+ Hits          1452      1462   +10     
Impacted Files Coverage Δ
src/dashboard/default-dashboard.ts 100.00% <100.00%> (ø)
src/model/manager/model-manager.ts 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -13,7 +13,7 @@ import { ModelOnDestroy, ModelOnInit } from './model-lifecycle-hooks';
* models.
*/
export class ModelManager {
private readonly modelInstanceMap: WeakMap<object, ModelInstanceData> = new WeakMap();
private readonly modelInstanceMap: Map<object, ModelInstanceData> = new Map();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Highlighting this change so others see it in the review.

Copy link
Contributor

Choose a reason for hiding this comment

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

Switching this to a strongly referenced map means we'd need to be more careful on memory leaks and manually manage this.

Copy link
Contributor

@aaron-steinfeld aaron-steinfeld left a comment

Choose a reason for hiding this comment

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

Left some impl comments, but potentially moot based on first comment.

* Returns a shallow copy array of model instances within a dashboard that match the
* argument model class
*/
getModelInstances<T extends object>(modelClass: Constructable<T>): object[];
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought your use case was to instantiate a model without a renderer? If that's the case, no changes are needed in this repo, just in hyperdash-angular to export certain APIs.

Copy link
Contributor

Choose a reason for hiding this comment

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

(i,e. model manager's programmatic instantiation APIs)

@@ -13,7 +13,7 @@ import { ModelOnDestroy, ModelOnInit } from './model-lifecycle-hooks';
* models.
*/
export class ModelManager {
private readonly modelInstanceMap: WeakMap<object, ModelInstanceData> = new WeakMap();
private readonly modelInstanceMap: Map<object, ModelInstanceData> = new Map();
Copy link
Contributor

Choose a reason for hiding this comment

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

Switching this to a strongly referenced map means we'd need to be more careful on memory leaks and manually manage this.

* Returns a shallow copy array of model instances that match the argument model class
*/
public getModelInstances<T extends object>(modelClass: Constructable<T>): object[] {
return Array.from(this.modelInstanceMap.keys()).filter(modelInstance => modelInstance instanceof modelClass);
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't match the behavior you're looking for. The model instance map in this singleton is all models, you're using this from the context of one dashboard. Instead, you'd want to pass in the root from that dashboard and then use get children to walk that model's tree.

@@ -27,8 +27,10 @@ export class ModelManager {
/**
* Returns a shallow copy array of model instances that match the argument model class
*/
public getModelInstances<T extends object>(modelClass: Constructable<T>): object[] {
return Array.from(this.modelInstanceMap.keys()).filter(modelInstance => modelInstance instanceof modelClass);
public getModelInstances<T extends object>(modelClass: Constructable<T>, root?: object): object[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

we'd never want to call this without root, and once you have root, you don't need to enumerate keys so you can revert the instancemap back to a weakmap.

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