Skip to content

Commit

Permalink
perf: improve TCData build since restrictions cause a lot of works fo…
Browse files Browse the repository at this point in the history
…r every call
  • Loading branch information
marco-prontera committed Dec 14, 2023
1 parent 7de61cc commit 488f147
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions modules/cmpapi/src/response/TCData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {Booleany} from './Booleany.js';
import {Response} from './Response.js';
import {EventStatus, CmpStatus} from '../status/index.js';

let restrictionCache: {[key: string]: Restrictions} = {};
export class TCData extends Response {

public tcString: string;
Expand Down Expand Up @@ -128,6 +129,15 @@ export class TCData extends Response {
*/
protected createRestrictions(purpRestrictions: PurposeRestrictionVector): Restrictions {

if (restrictionCache[CmpApiModel.tcString]) {

return restrictionCache[CmpApiModel.tcString];

}

// Prevent to store a lots of cached results
restrictionCache = {};

const retr = {};

if (purpRestrictions.numRestrictions > 0) {
Expand Down Expand Up @@ -156,6 +166,8 @@ export class TCData extends Response {

}

restrictionCache[CmpApiModel.tcString] = retr;

return retr;

};
Expand Down

0 comments on commit 488f147

Please sign in to comment.