tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
291
fork
atom
a tool for shared writing and social publishing
291
fork
atom
overview
issues
28
pulls
pipelines
use an advisory lock on token id on push
awarm.space
6 months ago
493f7a9d
b62af421
+7
1 changed file
expand all
collapse all
unified
split
app
api
rpc
[command]
push.ts
+7
app/api/rpc/[command]/push.ts
···
79
79
start = performance.now();
80
80
try {
81
81
await db.transaction(async (tx) => {
82
82
+
// Acquire transaction-scoped advisory lock on token ID
83
83
+
// Convert token ID to a stable integer for pg_advisory_xact_lock
84
84
+
const tokenHash = token.id.split("").reduce((acc, char) => {
85
85
+
return ((acc << 5) - acc + char.charCodeAt(0)) | 0;
86
86
+
}, 0);
87
87
+
await tx.execute(sql`SELECT pg_advisory_xact_lock(${tokenHash})`);
88
88
+
82
89
let clientGroupStart = performance.now();
83
90
let clientGroup = await getClientGroup(tx, pushRequest.clientGroupID);
84
91
timeGettingClientGroup = performance.now() - clientGroupStart;