diff --git a/API.md b/API.md index b0f9b84..533577a 100644 --- a/API.md +++ b/API.md @@ -19,6 +19,7 @@ - [5.2 Examples](#52-examples) - [5.3 Result](#53-result) - [JSON output: `/api/search/?q=`](#json-output-apisearchsearch-idqquery) + - [6. Caching](#6-caching) ## 1. APPCONF @@ -252,4 +253,16 @@ Search for a text in manuscipt descriptions: Results in: ```json -``` \ No newline at end of file +``` + +## 6. Caching + +Due to performance some of the API calls are cached. So calls like `/api/` +result in a cache for all entities of `` and their properties. + +If data is changed and the cache can be rebuild by adding a GET parameter +to the above API calls: + +- `cache`. Possible values are: + - `no` cache is rebuild if newer data exists + - `reset` cache is always rebuild (exception: cache is not rebuild if it is newer than 1 minute) \ No newline at end of file diff --git a/build.properties b/build.properties index 387f568..72d4243 100644 --- a/build.properties +++ b/build.properties @@ -1,11 +1,11 @@ -#Fri, 25 Sep 2020 18:18:04 +0200 +#Wed, 07 Oct 2020 15:54:23 +0200 project.version.major=1 project.version.minor=9 -project.version.patch=4 +project.version.patch=6 project.app.name=ediarum.web project.app.folder=. -repository.version=v1.1.1-28-gf46ddf8 +repository.version=v1.9.4-1-gb105fef -project.version.date=2020-09-25.18-18-04 +project.version.date=2020-10-07.15-54-23 diff --git a/build/ediarum.web_v1.9.4.2020-09-25.18-18-04.xar b/build/ediarum.web_v1.9.6.2020-10-07.15-54-23.xar similarity index 97% rename from build/ediarum.web_v1.9.4.2020-09-25.18-18-04.xar rename to build/ediarum.web_v1.9.6.2020-10-07.15-54-23.xar index 5f33f3b..afd282a 100644 Binary files a/build/ediarum.web_v1.9.4.2020-09-25.18-18-04.xar and b/build/ediarum.web_v1.9.6.2020-10-07.15-54-23.xar differ diff --git a/content/edweb-api.xql b/content/edweb-api.xql index fff3cd5..50161bf 100644 --- a/content/edweb-api.xql +++ b/content/edweb-api.xql @@ -93,21 +93,31 @@ declare function edwebapi:filter-list( declare function edwebapi:get-all( $app-target as xs:string, $limit as xs:string?, - $cache as xs:string + $cache as xs:string, + $with-filter as xs:boolean ) { let $object-types := edwebapi:get-config($app-target)//appconf:object/@xml:id let $found-objects := for $object-type in $object-types let $map := - edwebapi:load-map-from-cache( - "edwebapi:get-object-list", - [$app-target, $object-type, $limit], - if ($cache = "yes") - then () - else edwebapi:data-collection($app-target), - $cache = "no" - ) + if ($with-filter) + then + edwebapi:load-map-from-cache( + "edwebapi:get-object-list", + [$app-target, $object-type, $limit], + edwebapi:data-collection($app-target), + $cache = "no", + $cache = "reset" + ) + else + edwebapi:load-map-from-cache( + "edwebapi:get-object-list-without-filter", + [$app-target, $object-type, $limit], + edwebapi:data-collection($app-target), + $cache = "no", + $cache = "reset" + ) return $map?list return map:merge((map:entry("date-time", current-dateTime()), $found-objects)) @@ -211,7 +221,8 @@ declare function edwebapi:load-map-from-cache( $function-name as xs:string, $params as array(*), $data-collection as xs:string?, - $reload as xs:boolean? + $soft-reload as xs:boolean?, + $hard-reload as xs:boolean? ) as map(*) { let $node-set as node()* := @@ -233,27 +244,28 @@ declare function edwebapi:load-map-from-cache( let $cache-file-name := substring-after($function-name, ":")||"-" ||translate(string-join($params?*[.!='cache'], "-"),'/','__')||".json" let $load-cache := util:binary-doc($cache-collection||"/"||$cache-file-name) - let $load-from-cache := exists($load-cache) + let $cache-exists := exists($load-cache) let $load-map := - if($load-from-cache) + if($cache-exists) then parse-json(util:binary-to-string($load-cache)) else false() let $current-date-time := current-dateTime() let $cache-is-new := - if ($load-from-cache) + if ($cache-exists) then ($current-date-time < xs:dateTime($load-map?date-time) + xs:dayTimeDuration("PT1M")) else false() - let $load-from-cache := $load-from-cache and not($reload) let $cache-is-up-to-date := - if ($load-from-cache and count($node-set)=0) + if ($cache-exists and count($node-set)=0) then true() - else if ($load-from-cache) + else if ($cache-exists and $soft-reload) then let $since := $load-map?date-time let $last-modified := xmldb:find-last-modified-since($node-set, $since) return count($last-modified)=0 + else if ($cache-exists) + then true() else false() - let $load-from-cache := ($load-from-cache and $cache-is-up-to-date) or $cache-is-new + let $load-from-cache := $cache-is-new or (not($hard-reload) and $cache-is-up-to-date) let $apply-and-store := if ($load-from-cache) then () @@ -470,6 +482,7 @@ declare function edwebapi:eval-filters-for-object( $object-xml as node() ) as map(*) { + let $cache := "" let $filters := $object-def/appconf:filters/appconf:filter let $data-collection := edwebapi:data-collection($app-target) let $filter-values := @@ -493,7 +506,8 @@ declare function edwebapi:eval-filters-for-object( "edwebapi:get-relation-list", [$app-target, $rel-type-name, ()], $data-collection, - false() + $cache = "no", + $cache = "reset" ) let $items := $relations?list?*[?($rel-perspective) = $object?id] for $i in $items return @@ -856,10 +870,9 @@ declare function edwebapi:get-search-results( edwebapi:load-map-from-cache( "edwebapi:get-object-list", [$app-target, $object-type, $limit], - if ($cache = "yes") - then () - else edwebapi:data-collection($app-target), - $cache = "no" + edwebapi:data-collection($app-target), + $cache = "no", + $cache = "reset" ) return edwebapi:get-object-list-with-search( @@ -985,6 +998,7 @@ declare function edwebapi:get-relation-list( $limit as xs:string? ) as map(*) { + let $cache := "" let $config := edwebapi:get-config($app-target) let $relation-type := $config//appconf:relation[@xml:id=$relation-type-name] let $subject-type := $relation-type/@subject/string() @@ -1005,8 +1019,9 @@ declare function edwebapi:get-relation-list( edwebapi:load-map-from-cache( "edwebapi:get-object-list-without-filter", [$app-target, $object-type, $limit], - (), - false() + edwebapi:data-collection($app-target), + $cache = "no", + $cache = "reset" ) return $map?list?* (: "list-without-filter" :) @@ -1015,8 +1030,9 @@ declare function edwebapi:get-relation-list( edwebapi:load-map-from-cache( "edwebapi:get-object-list-without-filter", [$app-target, $subject-type, $limit], - (), - false() + edwebapi:data-collection($app-target), + $cache = "no", + $cache = "reset" ) return $map?list?* (: "list-without-filter" :) let $data-collection := edwebapi:data-collection($app-target) diff --git a/expath-pkg.xml b/expath-pkg.xml index efb4148..a54d629 100644 --- a/expath-pkg.xml +++ b/expath-pkg.xml @@ -1,5 +1,5 @@ - + ediarum.web http://www.bbaw.de/telota/software/ediarum/web/lib diff --git a/views/api/all-list.xql b/views/api/all-list.xql index 2239420..a26c281 100644 --- a/views/api/all-list.xql +++ b/views/api/all-list.xql @@ -21,10 +21,11 @@ let $id-type := else $id-type (: let $id-type := request:get-parameter("id-type", request:get-attribute("id-type")) :) -let $all-list := edwebapi:get-all($app-target, $limit, $cache) return if ($id-type = "all") then - $all-list + let $all-list := edwebapi:get-all($app-target, $limit, $cache, false()) + return $all-list else - map:remove($all-list, "date-time")?*[?filter?($id-type)||"" != ""] + let $all-list := edwebapi:get-all($app-target, $limit, $cache, true()) + return map:remove($all-list, "date-time")?*[?filter?($id-type)||"" != ""] diff --git a/views/api/object-list.xql b/views/api/object-list.xql index 4f8ceeb..c29ef47 100644 --- a/views/api/object-list.xql +++ b/views/api/object-list.xql @@ -57,30 +57,27 @@ let $result := edwebapi:load-map-from-cache( "edwebapi:get-object-list-without-filter", [$app-target, $object-type, $limit], - if ($cache = "yes") - then () - else edwebapi:data-collection($app-target), - $cache = "no" + edwebapi:data-collection($app-target), + $cache = "no", + $cache = "reset" ) else if ($is-object) then edwebapi:load-map-from-cache( "edwebapi:get-object-list", [$app-target, $object-type, $limit], - if ($cache = "yes") - then () - else edwebapi:data-collection($app-target), - $cache = "no" + edwebapi:data-collection($app-target), + $cache = "no", + $cache = "reset" ) else if ($is-relation) then edwebapi:load-map-from-cache( "edwebapi:get-relation-list", [$app-target, $object-type, $limit], - if ($cache = "yes") - then () - else edwebapi:data-collection($app-target), - $cache = "no" + edwebapi:data-collection($app-target), + $cache = "no", + $cache = "reset" ) else $object-type||" isn't defined for '"||$app-target||"'." return