Skip to content

Commit

Permalink
fix(browser): add cache for system info getter
Browse files Browse the repository at this point in the history
  • Loading branch information
wqcstrong committed Dec 4, 2024
1 parent 0003107 commit a841840
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/page-spy-browser/src/plugins/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,24 @@ export default class SystemPlugin implements PageSpyPlugin {
SystemPlugin.hasInitd = false;
}

private _cache: SpySystem.DataItem | null = null;

public async getSystemInfo() {
const features = await computeResult();
const info = {
system: {
ua: navigator.userAgent,
},
features,
} as SpySystem.DataItem;
const processedByUser = this.$pageSpyConfig?.dataProcessor?.system?.(info);
if (!this._cache) {
const features = await computeResult();
this._cache = {
system: {
ua: navigator.userAgent,
},
features,
} as SpySystem.DataItem;
}

const processedByUser = this.$pageSpyConfig?.dataProcessor?.system?.(
this._cache,
);

if (processedByUser === false) return null;
return makeMessage('system', info);
return makeMessage('system', this._cache);
}
}

0 comments on commit a841840

Please sign in to comment.