Skip to content

Commit

Permalink
fix caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Metauriel committed Oct 22, 2024
1 parent 2207567 commit dd954e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('School Controller (API)', () => {

beforeEach(async () => {
await cleanupCollections(em);
await em.clearCache('roles-cache');
await em.clearCache('roles-cache-teacher');
});

afterAll(async () => {
Expand Down
16 changes: 4 additions & 12 deletions apps/server/src/shared/repo/role/role.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,27 @@ export class RoleRepo extends BaseRepo<Role> {
const promise: Promise<Role> = this._em.findOneOrFail(
Role,
{ name },
{ cache: ['roles-cache', this.cacheExpiration] }
{ cache: [`roles-cache-${name}`, this.cacheExpiration] }
);
return promise;
}

async findById(id: EntityId): Promise<Role> {
const promise: Promise<Role> = this._em.findOneOrFail(
Role,
{ id },
{ cache: ['roles-cache', this.cacheExpiration] }
);
const promise: Promise<Role> = this._em.findOneOrFail(Role, { id }, { cache: this.cacheExpiration });
return promise;
}

async findByNames(names: RoleName[]): Promise<Role[]> {
const promise: Promise<Role[]> = this._em.find(
Role,
{ name: { $in: names } },
{ cache: ['roles-cache', this.cacheExpiration] }
{ cache: [`roles-cache-${names.join('-')}`, this.cacheExpiration] }
);
return promise;
}

async findByIds(ids: string[]): Promise<Role[]> {
const promise: Promise<Role[]> = this._em.find(
Role,
{ id: { $in: ids } },
{ cache: ['roles-cache', this.cacheExpiration] }
);
const promise: Promise<Role[]> = this._em.find(Role, { id: { $in: ids } }, { cache: this.cacheExpiration });
return promise;
}
}

0 comments on commit dd954e4

Please sign in to comment.