Skip to content

Commit

Permalink
wip: removing unneeded locking.
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes committed Aug 11, 2022
1 parent 3810cbb commit 0646286
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/discovery/Discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ class Discovery {
gestaltKey: GestaltKey,
): Promise<void> {
await this.db.withTransactionF(async (tran) => {
await tran.lock(gestaltKey);
const valueIterator = tran.iterator<GestaltKey>(
this.discoveryQueueDbPath,
{ valueAsBuffer: false },
Expand Down
10 changes: 7 additions & 3 deletions src/notifications/NotificationsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class NotificationsManager {
// Only keep the message if the sending node has the correct permissions
if (Object.keys(nodePerms.gestalt).includes('notify')) {
// If the number stored in notificationsDb >= 10000
let numMessages = await tran.get<number>(messageCountPath);
let numMessages = await tran.getForUpdate<number>(messageCountPath);
if (numMessages === undefined) {
numMessages = 0;
await tran.put(messageCountPath, 0);
Expand Down Expand Up @@ -315,7 +315,7 @@ class NotificationsManager {

await tran.lock(messageCountPath.toString());
const notificationIds = await this.getNotificationIds('all', tran);
const numMessages = await tran.get<number>(messageCountPath);
const numMessages = await tran.getForUpdate<number>(messageCountPath);
if (numMessages !== undefined) {
for (const id of notificationIds) {
await this.removeNotification(id, tran);
Expand Down Expand Up @@ -399,7 +399,11 @@ class NotificationsManager {
messageId: NotificationId,
tran: DBTransaction,
): Promise<void> {
const numMessages = await tran.get<number>([
await tran.lock([
...this.notificationsDbPath,
MESSAGE_COUNT_KEY,
].toString());
const numMessages = await tran.getForUpdate<number>([
...this.notificationsDbPath,
MESSAGE_COUNT_KEY,
]);
Expand Down

0 comments on commit 0646286

Please sign in to comment.