Skip to content

Commit 6df6a4f

Browse files
committed
[#167064659] Remove useless mutex during reset redis client lock
1 parent cc102ae commit 6df6a4f

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/services/redisUserMetadataStorage.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
taskify,
1616
tryCatch
1717
} from "fp-ts/lib/TaskEither";
18-
import { FiscalCode } from "italia-ts-commons/lib/strings";
1918

2019
const userMetadataPrefix = "USERMETA-";
2120
export const metadataNotFoundError = new Error("User Metadata not found");
@@ -54,8 +53,8 @@ export default class RedisUserMetadataStorage extends RedisStorageUtils
5453
if (raceCondition === false) {
5554
this.setOperations.add(user.fiscal_code);
5655
} else {
57-
// A duplicate redis client must be created only if the main client is already
58-
// in use into an optimistic lock update on the same key
56+
// A duplicated redis client must be created only if the main client is already
57+
// in use for another optimistic lock update on the same key to prevent performance drop
5958
duplicatedOrOriginalRedisClient = this.redisClient.duplicate();
6059
}
6160
this.mutex.release();
@@ -116,7 +115,7 @@ export default class RedisUserMetadataStorage extends RedisStorageUtils
116115
.run();
117116
raceCondition
118117
? duplicatedOrOriginalRedisClient.end(true)
119-
: await this.resetOperation(user.fiscal_code);
118+
: this.setOperations.delete(user.fiscal_code);
120119
return userMetadataWatchResult;
121120
}
122121

@@ -171,10 +170,4 @@ export default class RedisUserMetadataStorage extends RedisStorageUtils
171170
);
172171
});
173172
}
174-
175-
private async resetOperation(fiscalCode: FiscalCode): Promise<void> {
176-
await this.mutex.acquire();
177-
this.setOperations.delete(fiscalCode);
178-
this.mutex.release();
179-
}
180173
}

0 commit comments

Comments
 (0)