Skip to content
Snippets Groups Projects
Commit 1dc6ba86 authored by Steve Reis's avatar Steve Reis
Browse files

fix: User's cache reset after logout

parent 02e7e4b9
No related branches found
No related tags found
No related merge requests found
...@@ -324,7 +324,7 @@ export default class DataShieldConnector implements Connector { ...@@ -324,7 +324,7 @@ export default class DataShieldConnector implements Connector {
}); });
} }
async getDomains(_ids: string[], request: Request): Promise<Domain[]> { async getDomains(request: Request): Promise<Domain[]> {
const user = request.user as User; const user = request.user as User;
const sid = user && user.extraFields && user.extraFields['sid']; const sid = user && user.extraFields && user.extraFields['sid'];
......
...@@ -161,29 +161,27 @@ export default class ExaremeConnector implements Connector { ...@@ -161,29 +161,27 @@ export default class ExaremeConnector implements Connector {
} }
} }
async getDomains(ids: string[], request: Request): Promise<Domain[]> { async getDomains(request: Request): Promise<Domain[]> {
const path = this.options.baseurl + 'pathologies'; const path = this.options.baseurl + 'pathologies';
try { try {
const data = await firstValueFrom(this.get<Pathology[]>(request, path)); const data = await firstValueFrom(this.get<Pathology[]>(request, path));
return ( return (
data?.data data?.data.map((d): Domain => {
.filter((d) => !ids || ids.length == 0 || ids.includes(d.code)) const groups = this.flattenGroups(d.metadataHierarchy);
.map((d): Domain => {
const groups = this.flattenGroups(d.metadataHierarchy); return {
id: d.code,
return { label: d.label,
id: d.code, groups: groups,
label: d.label, rootGroup: dataToGroup(d.metadataHierarchy),
groups: groups, datasets: d.datasets ? d.datasets.map(dataToDataset) : [],
rootGroup: dataToGroup(d.metadataHierarchy), variables: d.metadataHierarchy
datasets: d.datasets ? d.datasets.map(dataToDataset) : [], ? this.flattenVariables(d.metadataHierarchy, groups)
variables: d.metadataHierarchy : [],
? this.flattenVariables(d.metadataHierarchy, groups) };
: [], }) ?? []
};
}) ?? []
); );
} catch (error) { } catch (error) {
throw new HttpException( throw new HttpException(
......
...@@ -63,12 +63,8 @@ export class EngineResolver { ...@@ -63,12 +63,8 @@ export class EngineResolver {
} }
@Query(() => [Domain]) @Query(() => [Domain])
async domains( async domains(@GQLRequest() req: Request) {
@GQLRequest() req: Request, return this.engineService.getDomains(req);
@Args('ids', { nullable: true, type: () => [String], defaultValue: [] })
ids: string[],
) {
return this.engineService.getDomains(ids, req);
} }
@Query(() => [Algorithm]) @Query(() => [Algorithm])
......
...@@ -31,6 +31,10 @@ import { FilterConfiguration } from './models/filter/filter-configuration'; ...@@ -31,6 +31,10 @@ import { FilterConfiguration } from './models/filter/filter-configuration';
import { FormulaOperation } from './models/formula/formula-operation.model'; import { FormulaOperation } from './models/formula/formula-operation.model';
import { Variable } from './models/variable.model'; import { Variable } from './models/variable.model';
const DOMAINS_CACHE_KEY = 'domains';
const ALGORITHMS_CACHE_KEY = 'experiments';
const CACHE_KEYS = [DOMAINS_CACHE_KEY, ALGORITHMS_CACHE_KEY];
/** /**
* Engine service. * Engine service.
* This class is used as a Proxy to the real Connector. * This class is used as a Proxy to the real Connector.
...@@ -102,17 +106,18 @@ export default class EngineService implements Connector { ...@@ -102,17 +106,18 @@ export default class EngineService implements Connector {
return result; return result;
} }
async getDomains(ids: string[], req: Request): Promise<Domain[]> { async getDomains(req: Request): Promise<Domain[]> {
const user = req?.user as User; const user = req?.user as User;
const key = user.id ? `domains-${ids.join('-')}-${user.id}` : undefined; const key = user.id ? `${DOMAINS_CACHE_KEY}-${user.id}` : undefined;
return this.getFromCacheOrCall<Domain[]>(key, () => return this.getFromCacheOrCall<Domain[]>(key, () =>
this.connector.getDomains(ids, req), this.connector.getDomains(req),
); );
} }
async getAlgorithms(req: Request): Promise<Algorithm[]> { async getAlgorithms(req: Request): Promise<Algorithm[]> {
const key = 'algorithms'; const user = req?.user as User;
const key = user.id ? `${ALGORITHMS_CACHE_KEY}-${user.id}` : undefined;
return this.getFromCacheOrCall<Algorithm[]>(key, () => return this.getFromCacheOrCall<Algorithm[]>(key, () =>
this.connector.getAlgorithms(req), this.connector.getAlgorithms(req),
...@@ -133,7 +138,7 @@ export default class EngineService implements Connector { ...@@ -133,7 +138,7 @@ export default class EngineService implements Connector {
): Promise<Variable[]> { ): Promise<Variable[]> {
if (!domainId || varIds.length === 0) return []; if (!domainId || varIds.length === 0) return [];
const domains = await this.getDomains([], request); const domains = await this.getDomains(request);
return ( return (
domains domains
...@@ -217,6 +222,13 @@ export default class EngineService implements Connector { ...@@ -217,6 +222,13 @@ export default class EngineService implements Connector {
} }
async logout?(req?: Request): Promise<void> { async logout?(req?: Request): Promise<void> {
const user = req?.user as User;
if (user && user.id)
CACHE_KEYS.map((key) => `${key}-${user.id}`).forEach((key) =>
this.cacheManager.del(key),
);
if (!this.connector.logout) throw new NotImplementedException(); if (!this.connector.logout) throw new NotImplementedException();
return this.connector.logout(req); return this.connector.logout(req);
} }
......
...@@ -24,10 +24,9 @@ export default interface Connector { ...@@ -24,10 +24,9 @@ export default interface Connector {
/** /**
* Get the list of domains along with a list of variables * Get the list of domains along with a list of variables
* @param ids - Ids to filter the domain needed
* @param req - Request - this is the request object from the HTTP request. * @param req - Request - this is the request object from the HTTP request.
*/ */
getDomains(ids: string[], req?: Request): Promise<Domain[]>; getDomains(req?: Request): Promise<Domain[]>;
/** /**
* Create and return a full detailed experiment * Create and return a full detailed experiment
......
...@@ -374,7 +374,7 @@ type ListExperiments { ...@@ -374,7 +374,7 @@ type ListExperiments {
type Query { type Query {
configuration: Configuration! configuration: Configuration!
domains(ids: [String!] = []): [Domain!]! domains: [Domain!]!
algorithms: [Algorithm!]! algorithms: [Algorithm!]!
formula: [FormulaOperation!]! formula: [FormulaOperation!]!
filter: FilterConfiguration! filter: FilterConfiguration!
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment