Index: db.scm ================================================================== --- db.scm +++ db.scm @@ -322,12 +322,12 @@ (dbstruct (make-dbr:dbstruct path: dbdir local: local))) dbstruct)) ;; Open the classic megatest.db file in toppath ;; -(define (db:open-megatest-db) - (let* ((dbpath (conc *toppath* "/megatest.db")) +(define (db:open-megatest-db #!key (path #f)) + (let* ((dbpath (or path (conc *toppath* "/megatest.db"))) (dbexists (file-exists? dbpath)) (db (db:lock-create-open dbpath (lambda (db) (db:initialize-main-db db) (db:initialize-run-id-db db)))) @@ -781,10 +781,33 @@ FOR EACH ROW BEGIN UPDATE run_stats SET last_update=(strftime('%s','now')) WHERE id=old.id; END;")) + +(define (db:cache-for-read-only source target) + (let* ((toppath (launch:setup)) + (cache-db (db:open-megatest-db path: target)) + (source-db (db:open-megatest-db path: source)) + (curr-time (current-seconds)) + (res '())) + (print source-db) + (begin + (if (not (file-exists? target)) + ((db:sync-tables (db:sync-main-list source-db) source-db cache-db) + (db:sync-tables db:sync-tests-only source-db cache-db) + (db:clean-up-rundb cache-db)) + ((sqlite3:for-each-row + (lambda (id release runname state status owner event_time comment fail_count pass_count ) + (set! res (cons (id release runname state status owner event_time comment fail_count pass_count ) res))) + (db:dbdat-get-db source-db) + "SELECT id, release, runname, state, status, owner, event_time, comment, fail_count, pass_count FROM runs;")) + ) + (print res) + (sqlite3:finalize! (db:dbdat-get-db cache-db)) + )) + ) ;; options: ;; ;; 'killservers - kills all servers ;; 'dejunk - removes junk records @@ -819,11 +842,11 @@ ;; clear out junk records ;; (if (member 'dejunk options) (begin (db:delay-if-busy mtdb) - (db:clean-up mtdb))) + (db:clean-up mtdb))) ;; adjust test-ids to fit into proper range ;; (if (member 'adj-testids options) (begin Index: megatest.scm ================================================================== --- megatest.scm +++ megatest.scm @@ -259,12 +259,14 @@ "-archive" "-since" "-fields" "-recover-test" ;; run-id,test-id - used internally to recover a test stuck in RUNNING state "-sort" - ) - (list "-h" "-help" "--help" + "-target-db" + "-source-db" + ) + (list "-h" "-help" "--help" "-manual" "-version" "-force" "-xterm" "-showkeys" @@ -277,11 +279,11 @@ "-daemonize" "-preclean" "-rerun-clean" "-rerun-all" "-clean-cache" - + "-cache-db" ;; misc "-repl" "-lock" "-unlock" "-list-servers" @@ -482,10 +484,19 @@ ;;====================================================================== ;; Misc general calls ;;====================================================================== +(if (args:get-arg "-cache-db") + (begin + (set! *didsomething* #t) + (let* ((temp-dir (or (args:get-arg "-target-db") (create-directory (conc "/tmp/" (getenv "USER") "/" (string-translate (current-directory) "/" "_"))))) + (target-db (conc temp-dir "/cached.db")) + (source-db (args:get-arg "-source-db"))) + + (db:cache-for-read-only source-db target-db)))) + ;; handle a clean-cache request as early as possible ;; (if (args:get-arg "-clean-cache") (begin (set! *didsomething* #t) ;; suppress the help output.