tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
298
fork
atom
a tool for shared writing and social publishing
298
fork
atom
overview
issues
31
pulls
3
pipelines
remove nested transaction and fact write loop
awarm.space
7 months ago
b62af421
3c05168b
+17
-28
1 changed file
expand all
collapse all
unified
split
src
replicache
cachedServerMutationContext.ts
+17
-28
src/replicache/cachedServerMutationContext.ts
reviewed
···
165
165
let flushStart = performance.now();
166
166
let timeInsertingEntities = 0;
167
167
let timeProcessingFactWrites = 0;
168
168
-
let timeTextMerging = 0;
169
169
-
let timeFactInserts = 0;
170
168
let timeDeletingEntities = 0;
171
169
let timeDeletingFacts = 0;
172
170
let timeCacheCleanup = 0;
···
186
184
f.type === "del" ? [] : [f.fact],
187
185
);
188
186
if (factWrites.length > 0) {
189
189
-
for (let f of factWrites) {
190
190
-
let factInsertStart = performance.now();
191
191
-
await tx.transaction((tx2) =>
192
192
-
tx2
193
193
-
.insert(facts)
194
194
-
.values({
195
195
-
id: f.id,
196
196
-
entity: f.entity,
197
197
-
data: driz.sql`${f.data}::jsonb`,
198
198
-
attribute: f.attribute,
199
199
-
})
200
200
-
.onConflictDoUpdate({
201
201
-
target: facts.id,
202
202
-
set: {
203
203
-
data: driz.sql`excluded.data`,
204
204
-
entity: driz.sql`excluded.entity`,
205
205
-
},
206
206
-
})
207
207
-
.catch((e) =>
208
208
-
console.log(`error on inserting fact: `, JSON.stringify(e)),
209
209
-
),
210
210
-
);
211
211
-
timeFactInserts += performance.now() - factInsertStart;
212
212
-
}
187
187
+
await tx
188
188
+
.insert(facts)
189
189
+
.values(
190
190
+
factWrites.map((f) => ({
191
191
+
id: f.id,
192
192
+
entity: f.entity,
193
193
+
data: driz.sql`${f.data}::jsonb`,
194
194
+
attribute: f.attribute,
195
195
+
})),
196
196
+
)
197
197
+
.onConflictDoUpdate({
198
198
+
target: facts.id,
199
199
+
set: {
200
200
+
data: driz.sql`excluded.data`,
201
201
+
entity: driz.sql`excluded.entity`,
202
202
+
},
203
203
+
});
213
204
}
214
205
timeProcessingFactWrites = performance.now() - factWritesStart;
215
206
···
261
252
==========================================
262
253
Entity Insertions (${entitiesCache.length} entities): ${timeInsertingEntities.toFixed(2)}ms
263
254
Fact Processing (${factWrites.length} facts): ${timeProcessingFactWrites.toFixed(2)}ms
264
264
-
- Text Merging: ${timeTextMerging.toFixed(2)}ms
265
265
-
- Fact Inserts (nested transactions): ${timeFactInserts.toFixed(2)}ms
266
255
Entity Deletions (${deleteEntitiesCache.length} entities): ${timeDeletingEntities.toFixed(2)}ms
267
256
Fact Deletions: ${timeDeletingFacts.toFixed(2)}ms
268
257
Cache Cleanup: ${timeCacheCleanup.toFixed(2)}ms