Skip to content

Commit 88752eb

Browse files
committed
rename and slighly refactor primeLoader more
1 parent d54d7f1 commit 88752eb

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

src/cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export interface CachedMethods<DType> {
5050
) => Promise<(DType | undefined)[]>;
5151
deleteFromCacheById: (id: string) => Promise<void>;
5252
dataLoader?: DataLoader<string, DType, string>;
53-
primeCache: (item: DType | DType[], ttl?: number) => void;
53+
primeLoader: (item: DType | DType[], ttl?: number) => void;
5454
}
5555

5656
export const createCachingMethods = <DType extends { id: string }>({
@@ -122,7 +122,7 @@ export const createCachingMethods = <DType extends { id: string }>({
122122
* Use this when running a query outside of the findOneById/findManyByIds methos
123123
* that automatically and transparently do this
124124
*/
125-
primeCache: (docs, ttl?: number) => {
125+
primeLoader: (docs, ttl?: number) => {
126126
docs = isArray(docs) ? docs : [docs];
127127
docs.forEach((doc) => {
128128
const key = doc.id;

src/datasource.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ export class CosmosDataSource<TData extends { id: string }, TContext = any>
2828
findManyByIds: CachedMethods<TData>["findManyByIds"] = placeholderHandler;
2929
deleteFromCacheById: CachedMethods<TData>["deleteFromCacheById"] = placeholderHandler;
3030
dataLoader: CachedMethods<TData>["dataLoader"];
31-
primeCache: CachedMethods<TData>["primeCache"] = placeholderHandler;
31+
primeLoader: CachedMethods<TData>["primeLoader"] = placeholderHandler;
3232

3333
async findManyByQuery(query: SqlQuerySpec | string, { ttl }: FindArgs = {}) {
3434
const results = await this.container.items.query<TData>(query).fetchAll();
3535
// prime these into the dataloader and maybe the cache
3636
if (this.dataLoader && results.resources) {
37-
results.resources.forEach((r) => {
38-
this.primeCache(r, ttl);
39-
});
37+
this.primeLoader(results.resources, ttl);
4038
}
4139
return results.resources;
4240
}

0 commit comments

Comments
 (0)