Created
January 29, 2016 20:30
-
-
Save ableasdale/e20fabe493cb707d05aa to your computer and use it in GitHub Desktop.
MarkLogic - Batch Change Perms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| xquery version "1.0-ml"; | |
| declare function local:doWork( $cnt as xs:integer, $start as xs:integer, $end as xs:integer, $uris as xs:string* ){ | |
| xdmp:log(fn:concat("permission-change database:" , " total-cnt:", $cnt, " start:", $start, " end:", $end, " start:", xdmp:eval("fn:current-time()"))), | |
| for $i in $uris return xdmp:document-set-permissions($i,xdmp:permission("read-only","read")), | |
| xdmp:commit(), | |
| xdmp:log(fn:concat("permission-change database: ", " total-cnt:", $cnt, " start:", $start, " end:", $end, " finished:", xdmp:eval("fn:current-time()"), " Elapsed:", xdmp:elapsed-time() )) | |
| }; | |
| (: get start time of program run :) | |
| let $_ := xdmp:log("StartOfRun") | |
| let $curTime := xdmp:eval("fn:current-time()") | |
| let $option := | |
| <options xmlns="xdmp:eval"> | |
| <transaction-mode>update</transaction-mode> | |
| </options> | |
| let $chunk := 10000 | |
| let $_ := | |
| let $cnt := fn:count( cts:uris( (), (), (), (), () )) | |
| let $loop := xs:integer(fn:ceiling ( $cnt ) div $chunk) + 1 | |
| for $i in ( 1400 to $loop ) | |
| let $pos := ($i -1) * $chunk + 1 | |
| let $end := $pos + $chunk - 1 | |
| let $uris := cts:values(cts:uri-reference(), "/", (), (), (), ())[ $pos to $end ] | |
| return | |
| xdmp:spawn-function( | |
| function() { | |
| local:doWork( $cnt, $pos, $end, $uris) | |
| }, | |
| $option | |
| ) | |
| let $endTime := xdmp:eval("fn:current-time()") | |
| let $output := fn:concat("permission-change database: master: start-time", $curTime, " end-time: ",$endTime, " elapsed-time:", xdmp:elapsed-time()) | |
| return (xdmp:log( $output ), $output ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment