Skip to content

Commit 14869e7

Browse files
ryanjdewMarkLogic Builder
authored andcommitted
DHFPROD-3400: Don't check the same URIs repeatedly for additional merges
1 parent 562e05d commit 14869e7

File tree

1 file changed

+29
-27
lines changed
  • marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.smart-mastering/impl

1 file changed

+29
-27
lines changed

marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.smart-mastering/impl/process.xqy

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -152,33 +152,35 @@ declare function proc-impl:expand-uris-for-merge(
152152
) (: as xs:string* ~leaving off for tail recursion~ :)
153153
{
154154
let $additional-uris :=
155-
for $merge-uri in $current-uris
156-
return
157-
if (map:contains($matches,$merge-uri)) then
158-
map:get($matches, $merge-uri)/result[@action=$const:MERGE-ACTION]/@uri ! fn:string(.)
159-
else
160-
let $_lock-for-update := merge-impl:lock-for-update($merge-uri)
161-
let $results :=
162-
match-impl:find-document-matches-by-options(
163-
fn:doc($merge-uri),
164-
$matching-options,
165-
1,
166-
$max-scan,
167-
$merge-threshold,
168-
(: don't include detailed match information :)
169-
fn:false(),
170-
if ($filter-query instance of cts:true-query) then
171-
cts:not-query(cts:document-query($accumlated-uris))
172-
else
173-
cts:and-not-query($filter-query, cts:document-query($accumlated-uris)),
174-
(: return results :)
175-
fn:true()
176-
)[result/@action = $const:MERGE-ACTION]
177-
where fn:exists($results)
178-
return (
179-
map:put($matches, $merge-uri, $results),
180-
$results/result[@action=$const:MERGE-ACTION]/@uri ! fn:string(.)
181-
)
155+
fn:distinct-values(
156+
for $merge-uri in $current-uris
157+
return
158+
if (map:contains($matches, $merge-uri)) then
159+
map:get($matches, $merge-uri)/result[@action = $const:MERGE-ACTION]/@uri ! fn:string(.)
160+
else
161+
let $_lock-for-update := merge-impl:lock-for-update($merge-uri)
162+
let $results :=
163+
match-impl:find-document-matches-by-options(
164+
fn:doc($merge-uri),
165+
$matching-options,
166+
1,
167+
$max-scan,
168+
$merge-threshold,
169+
(: don't include detailed match information :)
170+
fn:false(),
171+
if ($filter-query instance of cts:true-query) then
172+
cts:not-query(cts:document-query($accumlated-uris))
173+
else
174+
cts:and-not-query($filter-query, cts:document-query($accumlated-uris)),
175+
(: return results :)
176+
fn:true()
177+
)[result/@action = $const:MERGE-ACTION]
178+
where fn:exists($results)
179+
return (
180+
map:put($matches, $merge-uri, $results),
181+
$results/result[@action = $const:MERGE-ACTION]/@uri ! fn:string(.)
182+
)
183+
)
182184
let $new-uris := $additional-uris[fn:not(. = $accumlated-uris)]
183185
return
184186
if (fn:empty($new-uris)) then

0 commit comments

Comments
 (0)