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 {
});
}
async getDomains(_ids: string[], request: Request): Promise<Domain[]> {
async getDomains(request: Request): Promise<Domain[]> {
const user = request.user as User;
const sid = user && user.extraFields && user.extraFields['sid'];
......
......@@ -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';
try {
const data = await firstValueFrom(this.get<Pathology[]>(request, path));
return (
data?.data
.filter((d) => !ids || ids.length == 0 || ids.includes(d.code))
.map((d): Domain => {
const groups = this.flattenGroups(d.metadataHierarchy);
return {
id: d.code,
label: d.label,
groups: groups,
rootGroup: dataToGroup(d.metadataHierarchy),
datasets: d.datasets ? d.datasets.map(dataToDataset) : [],
variables: d.metadataHierarchy
? this.flattenVariables(d.metadataHierarchy, groups)
: [],
};
}) ?? []
data?.data.map((d): Domain => {
const groups = this.flattenGroups(d.metadataHierarchy);
return {
id: d.code,
label: d.label,
groups: groups,
rootGroup: dataToGroup(d.metadataHierarchy),
datasets: d.datasets ? d.datasets.map(dataToDataset) : [],
variables: d.metadataHierarchy
? this.flattenVariables(d.metadataHierarchy, groups)
: [],
};
}) ?? []
);
} catch (error) {
throw new HttpException(
......
......@@ -63,12 +63,8 @@ export class EngineResolver {
}
@Query(() => [Domain])
async domains(
@GQLRequest() req: Request,
@Args('ids', { nullable: true, type: () => [String], defaultValue: [] })
ids: string[],
) {
return this.engineService.getDomains(ids, req);
async domains(@GQLRequest() req: Request) {
return this.engineService.getDomains(req);
}
@Query(() => [Algorithm])
......
......@@ -31,6 +31,10 @@ import { FilterConfiguration } from './models/filter/filter-configuration';
import { FormulaOperation } from './models/formula/formula-operation.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.
* This class is used as a Proxy to the real Connector.
......@@ -102,17 +106,18 @@ export default class EngineService implements Connector {
return result;
}
async getDomains(ids: string[], req: Request): Promise<Domain[]> {
async getDomains(req: Request): Promise<Domain[]> {
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, () =>
this.connector.getDomains(ids, req),
this.connector.getDomains(req),
);
}
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, () =>
this.connector.getAlgorithms(req),
......@@ -133,7 +138,7 @@ export default class EngineService implements Connector {
): Promise<Variable[]> {
if (!domainId || varIds.length === 0) return [];
const domains = await this.getDomains([], request);
const domains = await this.getDomains(request);
return (
domains
......@@ -217,6 +222,13 @@ export default class EngineService implements Connector {
}
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();
return this.connector.logout(req);
}
......
......@@ -24,10 +24,9 @@ export default interface Connector {
/**
* 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.
*/
getDomains(ids: string[], req?: Request): Promise<Domain[]>;
getDomains(req?: Request): Promise<Domain[]>;
/**
* Create and return a full detailed experiment
......
......@@ -374,7 +374,7 @@ type ListExperiments {
type Query {
configuration: Configuration!
domains(ids: [String!] = []): [Domain!]!
domains: [Domain!]!
algorithms: [Algorithm!]!
formula: [FormulaOperation!]!
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