Hello,
I am having noticeable performance degradation for updating existing
database in this function with Basex 81. I can say this function never
finish with 81. But when I replace nodes call with file:append (writing
result to a file), I can see it is slowness.
But Basex_79 is much faster than Basex81 with regard to this update and
finish this function quickly without any issue.
I like to upgrade to 81 but because of this issue I could not.
Can you help me?
declare %updating function local:addCRMSegmentsIntoProducts ()
{
let $allProds := fn:doc("AccumulatedProducts")
let $segments :=
("Aburcubur","Ãay_Kahve","İçecek","Karma_Az","Meyve_Sebze","Saç_Bakım","Süt_Su-Madeaze_Tüketim","Temizlik")
let $productsMap :=
map:new(
for $rec in $allProds//doc
let $prodIDField := $rec/field[@name eq "ProductID"]
let $pid := $prodIDField/text()
return
map:entry($pid,$prodIDField))
for tumbling window $prodGroup in fn:doc("CRMSegments")//record
start $first next $second when fn:true()
end $last next $beyond when $last/PRODUCT_ID ne $beyond/PRODUCT_ID
let $pid := $prodGroup[1]/PRODUCT_ID
return
let $prodEntry := map:get($productsMap,$pid)/..
return
if (fn:empty($prodEntry)) then ()
else
let $segData :=
for $segGroup in $prodGroup
let $sid := $segGroup/SON_SEGMENT/text()
let $sid :=
fn:concat("10",fn:index-of($segments,$sid))
group by $sid
return
let $segAmount := sum($segGroup//AMOUNT/text())
let $segOrderCount := sum($segGroup//ORDER_COUNT)
let $segFields := (<field
name="SegAmount_{$sid}">{$segAmount}</field>,
<field
name="SegOrderCount_{$sid}">{$segOrderCount}</field>)
return $segFields
return
insert nodes ($segData) as last into $prodEntry
};