Skip to content

Commit 7a086fc

Browse files
authored
Merge pull request #322 from NillionNetwork/feat/use-ring-buffer-in-user-audit-log
2 parents e932363 + 68a16fc commit 7a086fc

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/api/src/users/users.repository.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import {
2525
type UUID,
2626
} from "mongodb";
2727

28+
const MAX_USER_LOGS = 1000;
29+
2830
/**
2931
* Upsert user document.
3032
*/
@@ -60,8 +62,11 @@ export function upsert(
6062
data: {
6163
$each: data,
6264
},
65+
},
66+
$push: {
6367
logs: {
6468
$each: logs,
69+
$slice: -MAX_USER_LOGS,
6570
},
6671
},
6772
};
@@ -121,9 +126,10 @@ export function removeData(
121126
},
122127
},
123128
},
124-
$addToSet: {
129+
$push: {
125130
logs: {
126131
$each: UserLoggerMapper.toDeleteDataLogs(data),
132+
$slice: -MAX_USER_LOGS,
127133
},
128134
},
129135
};
@@ -157,6 +163,7 @@ export function updateUserLogs(
157163
$push: {
158164
logs: {
159165
$each: logs,
166+
$slice: -MAX_USER_LOGS,
160167
},
161168
},
162169
};

0 commit comments

Comments
 (0)