Skip to content

Move Module Cache outside of resource#696

Merged
tintinthong merged 1 commit into
mainfrom
cs-6056-remove-module-meta-cache
Oct 4, 2023
Merged

Move Module Cache outside of resource#696
tintinthong merged 1 commit into
mainfrom
cs-6056-remove-module-meta-cache

Conversation

@tintinthong

@tintinthong tintinthong commented Sep 30, 2023

Copy link
Copy Markdown
Contributor

This PR moves cache into service rather than residing in the resource

The original motive of this is so that other resources can consume this if needed. Here is the comment #656 (comment)

@tintinthong
tintinthong force-pushed the cs-6056-remove-module-meta-cache branch from f247fa6 to b881e2d Compare September 30, 2023 13:00
@tintinthong tintinthong changed the title Cs-6056-remove-module-meta-cache cs-6056-remove-module-meta-cache Sep 30, 2023
@github-actions

github-actions Bot commented Sep 30, 2023

Copy link
Copy Markdown
Contributor

Test Results

394 tests  ±0   387 ✔️ ±0   6m 1s ⏱️ +18s
    1 suites ±0       7 💤 ±0 
    1 files   ±0       0 ±0 

Results for commit c9c9252. ± Comparison against base commit 6108d83.

♻️ This comment has been updated with latest results.

}

let response = await this.loaderService.loader.fetch(fileURL, {
headers: { Accept: SupportedMimeType.CardSource },

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It seems that this was not the issue breaking test altho I thought it was at one point so I just reverted here

@habdelra habdelra Oct 2, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this seems like a bad assumption. how do you know that URL that is being requested is for card-source? This service is called "realm-info-service" it doesn't seem to indicate that this is only for card sources. Perhaps the accept header should be part of the parameters if this is necessary

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

if I were to use the realmInfo provider, I'd need to do a fetch for card source. I can use a different method and a different cache so we will not make this bad assumption. But the method that is called fetchExtension can be used for CardSource

@habdelra habdelra Oct 2, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

having these implicit requirements on the callers feels like it could be the source of bugs if people don't clearly understand how to use this API. I would suggest that just make the accept header explicit by requiring callers to specify it when they provide the URL to get the realm info. the accept header is part of how you ask for resources from the realm server anyways--let's just make that clear in our API for this service


import LoaderService from '@cardstack/host/services/loader-service';

export default class ModuleInfoService extends Service {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't understand why you need this service--isn't this what realm info service is doing? why can't you just move the cache into that service?

@tintinthong tintinthong Oct 2, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am fine with that. I considered that initially because the things it does is so similar to the realmInfoProvider but just felt that the naming purpose wasnt quite right. I can go ahead with that -- it does reduce code and caches

@habdelra habdelra Oct 2, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this to cache 302 redirects? seems like a premature optimization to me. Until we know that is a real issue i would suggest that we should eliminate these lines of code.

Comment on lines +15 to +18
let response = await this.loaderService.loader.fetch(moduleIdentifier, {
headers: { Accept: SupportedMimeType.CardSource },
});
let realmURL = response.headers.get('x-boxel-realm-url');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's not reinvent the wheel and use the realm-info service here

@habdelra

habdelra commented Oct 2, 2023

Copy link
Copy Markdown
Contributor

just to be clear, my comment around module scope did not mean move this into a service. It simply meant move the cache one block higher in the scope of the resource you already had (supeer simple change), so that instead of having:

export class CardType extends Resource<Args> {
  moduleMetaCache: Map<string, { extension: string; realmInfo: RealmInfo }> = new Map();
}

you would have:

const moduleMetaCache: Map<string, { extension: string; realmInfo: RealmInfo }> = new Map();

export class CardType extends Resource<Args> {
  ...
}

that way the cache is shared by all instances of the card type resource instead of only within a single instance. but i can see that if you want the cache to be shared by things that are not CardType resources, then caching in a service makes sense. but given what actually consumes this, i think making this a service is premature at this point

@tintinthong
tintinthong force-pushed the cs-6056-remove-module-meta-cache branch from d80dd41 to c9c9252 Compare October 3, 2023 06:12
@tintinthong

Copy link
Copy Markdown
Contributor Author

just to be clear, my comment around module scope did not mean move this into a service. It simply meant move the cache one block higher in the scope of the resource you already had (supeer simple change), so that instead of having:

export class CardType extends Resource<Args> {
  moduleMetaCache: Map<string, { extension: string; realmInfo: RealmInfo }> = new Map();
}

you would have:

const moduleMetaCache: Map<string, { extension: string; realmInfo: RealmInfo }> = new Map();

export class CardType extends Resource<Args> {
  ...
}

that way the cache is shared by all instances of the card type resource instead of only within a single instance. but i can see that if you want the cache to be shared by things that are not CardType resources, then caching in a service makes sense. but given what actually consumes this, i think making this a service is premature at this point

Ok I have made a change based upon this ultimately just moving the cache into module scope. I didn't use the realm info service and didn't create another service

@tintinthong
tintinthong requested a review from habdelra October 3, 2023 06:16

@habdelra habdelra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice. very tight (low LOC) 👍

@tintinthong tintinthong changed the title cs-6056-remove-module-meta-cache Move Module Cache Oct 3, 2023
@tintinthong tintinthong changed the title Move Module Cache Move Module Cache into outer scope Oct 3, 2023
@tintinthong tintinthong changed the title Move Module Cache into outer scope Move Module Cache outside of resource Oct 3, 2023
@tintinthong
tintinthong merged commit 1a33938 into main Oct 4, 2023
@delete-merged-branch
delete-merged-branch Bot deleted the cs-6056-remove-module-meta-cache branch October 4, 2023 02:21
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