Skip to content

Commit

Permalink
fn:starts-with is faster than fn:matches
Browse files Browse the repository at this point in the history
Deciding whether it is a CC docname or not, we don’t need to use a full regular expression.
Takes us from 7.2s to about 6.65s.
  • Loading branch information
alanpaxton authored and adamretter committed Nov 9, 2023
1 parent 5e5d062 commit 6e81a14
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions db/EIDO/data/edit/craft-connector-util.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ xquery version "3.1";
module namespace ccu = "https://ns.eidohealthcare.com/existdb/craft-connector-util";

declare %private variable $ccu:regex-craft-connector-docname as xs:string := "procedure\.([A-Z0-9_]+)_([a-z]{2,3}(?:-[A-Z]{2})?)_([a-z]+)_(full|reduced)_([0-9]+\.[0-9]+(?:\.[0-9]+)?)";
declare %private variable $ccu:regex-probably-craft-connector-docname as xs:string := "procedure\..*";
declare %private variable $ccu:craft-connector-docname-prefix as xs:string := "procedure.";
declare variable $ccu:source.craft-connector as xs:string := "eido-craft-connector";
declare variable $ccu:source.existdb-editorial as xs:string := "eido-existdb-editorial";

Expand Down Expand Up @@ -37,7 +39,8 @@ declare variable $ccu:craft-library-to-territory-map as map(xs:string, xs:string
: @return true if it matches the pattern generated by Craft Connector, false otherwise
:)
declare function ccu:is-craft-connector-docname($docname as xs:string) as xs:boolean {
fn:matches($docname, $ccu:regex-craft-connector-docname)
fn:starts-with($docname, $ccu:craft-connector-docname-prefix)
(: fn:matches($docname, $ccu:regex-probably-craft-connector-docname) :)
};

(:~
Expand Down Expand Up @@ -86,12 +89,12 @@ declare function ccu:extract-components-from-craft-connector-docname($docname as
: @return a map with the keys: source, code, and docnum.
:)
declare function ccu:extract-components-from-editorial-docname($docname as xs:string) as map(xs:string, xs:string) {
let $subst := fn:replace($docname, ".xml", "") return (
let $component := fn:replace($docname, ".xml", "") return
map {
"source": $ccu:source.existdb-editorial,
"code": $subst,
"docnum": $subst
})
"code": $component,
"docnum": $component
}
};

(:~
Expand Down

0 comments on commit 6e81a14

Please sign in to comment.