a tool for shared writing and social publishing

remove nested transaction and fact write loop

+17 -28
+17 -28
src/replicache/cachedServerMutationContext.ts
··· 165 165 let flushStart = performance.now(); 166 166 let timeInsertingEntities = 0; 167 167 let timeProcessingFactWrites = 0; 168 - let timeTextMerging = 0; 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 - for (let f of factWrites) { 190 - let factInsertStart = performance.now(); 191 - await tx.transaction((tx2) => 192 - tx2 193 - .insert(facts) 194 - .values({ 195 - id: f.id, 196 - entity: f.entity, 197 - data: driz.sql`${f.data}::jsonb`, 198 - attribute: f.attribute, 199 - }) 200 - .onConflictDoUpdate({ 201 - target: facts.id, 202 - set: { 203 - data: driz.sql`excluded.data`, 204 - entity: driz.sql`excluded.entity`, 205 - }, 206 - }) 207 - .catch((e) => 208 - console.log(`error on inserting fact: `, JSON.stringify(e)), 209 - ), 210 - ); 211 - timeFactInserts += performance.now() - factInsertStart; 212 - } 187 + await tx 188 + .insert(facts) 189 + .values( 190 + factWrites.map((f) => ({ 191 + id: f.id, 192 + entity: f.entity, 193 + data: driz.sql`${f.data}::jsonb`, 194 + attribute: f.attribute, 195 + })), 196 + ) 197 + .onConflictDoUpdate({ 198 + target: facts.id, 199 + set: { 200 + data: driz.sql`excluded.data`, 201 + entity: driz.sql`excluded.entity`, 202 + }, 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 - - Text Merging: ${timeTextMerging.toFixed(2)}ms 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