v1.0.101: шаг8 — batch SELECT для UPDATE вместо N+1
This commit is contained in:
+21
-6
@@ -67,6 +67,25 @@
|
||||
<!--- Применить операции --->
|
||||
<cfset summary = {added: 0, updated: 0, deleted: 0, unresolved: 0}>
|
||||
|
||||
<!--- Pre-fetch: собрать все target_hash для UPDATE, один SELECT вместо N+1 --->
|
||||
<cfset updateHashes = []>
|
||||
<cfloop array="#ops#" index="op">
|
||||
<cfif op.action EQ "UPDATE">
|
||||
<cfset arrayAppend(updateHashes, op.target_hash)>
|
||||
</cfif>
|
||||
</cfloop>
|
||||
<cfset oldValues = {}>
|
||||
<cfif arrayLen(updateHashes) GT 0>
|
||||
<cfquery name="oldBatch" datasource="baza">
|
||||
SELECT name_hash, price, qty, sum, date_start FROM spec_current
|
||||
WHERE contract_id = <cfqueryparam value="#url.contract_id#" cfsqltype="cf_sql_varchar">
|
||||
AND name_hash IN (<cfloop from="1" to="#arrayLen(updateHashes)#" index="hi"><cfif hi GT 1>,</cfif><cfqueryparam value="#updateHashes[hi]#" cfsqltype="cf_sql_varchar"></cfloop>)
|
||||
</cfquery>
|
||||
<cfloop query="oldBatch">
|
||||
<cfset oldValues[oldBatch.name_hash] = {price: oldBatch.price, qty: oldBatch.qty, sum: oldBatch.sum, date_start: oldBatch.date_start}>
|
||||
</cfloop>
|
||||
</cfif>
|
||||
|
||||
<cfloop array="#ops#" index="op">
|
||||
<cfset seq++>
|
||||
<cfset action = op.action>
|
||||
@@ -110,14 +129,10 @@
|
||||
|
||||
<cfelseif action EQ "UPDATE">
|
||||
<cfset th = op.target_hash>
|
||||
<cfquery name="old" datasource="baza">
|
||||
SELECT price, qty, sum, date_start FROM spec_current
|
||||
WHERE contract_id = <cfqueryparam value="#url.contract_id#" cfsqltype="cf_sql_varchar">
|
||||
AND name_hash = <cfqueryparam value="#th#" cfsqltype="cf_sql_varchar">
|
||||
</cfquery>
|
||||
<cfif old.recordCount EQ 0>
|
||||
<cfif NOT structKeyExists(oldValues, th)>
|
||||
<cfthrow message="UPDATE target not found: #th#">
|
||||
</cfif>
|
||||
<cfset old = oldValues[th]>
|
||||
<cfset nv = structKeyExists(op, 'new_values') ? op.new_values : {}>
|
||||
<cfset newPrice = structKeyExists(nv, 'price') AND isNumeric(nv.price) ? nv.price : old.price>
|
||||
<cfset newQty = structKeyExists(nv, 'qty') AND isNumeric(nv.qty) ? nv.qty : old.qty>
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
<body>
|
||||
<div class="topbar">
|
||||
<img src="/nubes-logo.svg" alt="Nubes">
|
||||
<span class="title">Сверка договоров — LLM AI-driven Event Sourcing <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.0.100 — Lucee</span></span>
|
||||
<span class="title">Сверка договоров — LLM AI-driven Event Sourcing <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.0.101 — Lucee</span></span>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
|
||||
Reference in New Issue
Block a user