Skip to content

Commit

Permalink
use WeakMap
Browse files Browse the repository at this point in the history
  • Loading branch information
sjvans committed Oct 31, 2024
1 parent 04b3de3 commit 2736f63
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/modification.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const _getDataWithAppliedTransitions = (data, req) => {
const addDiffToCtx = async function (req) {
// store diff in audit data structure at context
const _audit = (req.context._audit ??= {})
if (!_audit.diffs) _audit.diffs = new Map()
if (!_audit.diffs) _audit.diffs = new WeakMap()

// get diff
let diff = (await req.diff()) || {}
Expand Down Expand Up @@ -184,7 +184,7 @@ const _calcModificationLogsHandler = async function (req, beforeWrite, that) {
const modificationLogs = _getDataModificationLogs(req, that, _audit.diffs.get(mapKey), beforeWrite)

// store modificationLogs in audit data structure at context
if (!_audit.modificationLogs) _audit.modificationLogs = new Map()
if (!_audit.modificationLogs) _audit.modificationLogs = new WeakMap()
const existingLogs = _audit.modificationLogs.get(mapKey) || {}
_audit.modificationLogs.set(mapKey, Object.assign(existingLogs, modificationLogs))

Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ const getDataSubject = (entity, model) => {
const _getDataSubjectsMap = req => {
const mapKey = getMapKeyForCurrentRequest(req)
const _audit = (req.context._audit ??= {})
if (!_audit.dataSubjects) _audit.dataSubjects = new Map()
if (!_audit.dataSubjects) _audit.dataSubjects = new WeakMap()
if (!_audit.dataSubjects.has(mapKey)) _audit.dataSubjects.set(mapKey, new Map())
return _audit.dataSubjects.get(mapKey)
}
Expand Down

0 comments on commit 2736f63

Please sign in to comment.