Index: db.scm ================================================================== --- db.scm +++ db.scm @@ -494,11 +494,11 @@ finalres)))) (define (db:set-comment-for-run db run-id comment) (sqlite3:execute db "UPDATE runs SET comment=? WHERE id=?;" comment run-id)) -;; does not (obviously!) removed dependent data. +;; does not (obviously!) removed dependent data. But why not!!? (define (db:delete-run db run-id) (sqlite3:execute db "DELETE FROM runs WHERE id=?;" run-id)) (define (db:update-run-event_time db run-id) (sqlite3:execute db "UPDATE runs SET event_time=strftime('%s','now') WHERE id=?;" run-id)) @@ -633,25 +633,30 @@ (sqlite3:execute tdb "DELETE FROM test_steps;") (sqlite3:execute tdb "DELETE FROM test_data;") (sqlite3:finalize! tdb))))) ;; -(define (db:delete-test-records db tdb test-id) +(define (db:delete-test-records db tdb test-id #!key (force #f)) (if tdb (begin (sqlite3:execute tdb "DELETE FROM test_steps;") (sqlite3:execute tdb "DELETE FROM test_data;"))) ;; (sqlite3:execute db "DELETE FROM tests WHERE id=?;" test-id)) (if db (begin (sqlite3:execute db "DELETE FROM test_steps WHERE test_id=?;" test-id) (sqlite3:execute db "DELETE FROM test_data WHERE test_id=?;" test-id) - (sqlite3:execute db "UPDATE tests SET state='DELETED',status='n/a' WHERE test_id=?;" test-id)))) + (if force + (sqlite3:execute db "DELETE FROM tests WHERE id=?;" test-id) + (sqlite3:execute db "UPDATE tests SET state='DELETED',status='n/a' WHERE id=?;" test-id))))) + +(define (db:delete-tests-for-run db run-id) + (sqlite3:execute db "DELETE FROM tests WHERE run_id=?;" run-id)) (define (db:delete-old-deleted-test-records db) (let ((targtime (- (current-seconds)(* 30 24 60 60)))) ;; one month in the past - (sqlite3:exectute db "DELETE FROM tests WHERE state='DELETED' AND event_timenumber last-delete-str) #f))) + (if (and last-delete (> last-delete *last-test-cache-delete*)) + (begin + (set! *test-info* (make-hash-table)) + (set! *test-id-cache* (make-hash-table)) + (set! *last-test-cache-delete* last-delete) + (debug:print 4 "INFO: Clearing test data cache")))) (if (not test-id) (begin (debug:print 4 "INFO: db:get-test-info-by-id called with test-id=" test-id) #f) - (let ((res (hash-table-ref/default *test-info* test-id #f))) + (let* ((res (hash-table-ref/default *test-info* test-id #f))) (if res (db:patch-tdb-data-into-test-info db test-id res) ;; if no cached value then full read and write to cache (begin (sqlite3:for-each-row Index: runs.scm ================================================================== --- runs.scm +++ runs.scm @@ -726,20 +726,22 @@ (open-run-close db:test-set-state-status-by-id db (db:test-get-id test) (car state-status)(cadr state-status) #f))))) tests))) ;; remove the run if zero tests remain (if (eq? action 'remove-runs) - (let ((remtests (db:get-tests-for-run db (db:get-value-by-header run header "id") #f #f '() '()))) + (let ((remtests (db:get-tests-for-run db (db:get-value-by-header run header "id") #f #f '("DELETED") '("n/a") not-in: #t))) (if (null? remtests) ;; no more tests remaining (let* ((dparts (string-split lasttpath "/")) (runpath (conc "/" (string-intersperse (take dparts (- (length dparts) 1)) "/")))) - (debug:print 1 "Removing run: " runkey " " (db:get-value-by-header run header "runname")) + (debug:print 1 "Removing run: " runkey " " (db:get-value-by-header run header "runname") " and related record") (db:delete-run db run-id) ;; This is a pretty good place to purge old DELETED tests + (db:delete-tests-for-run db run-id) (db:delete-old-deleted-test-records db) + (db:set-var db "DELETED_TESTS" (current-seconds)) ;; need to figure out the path to the run dir and remove it if empty ;; (if (null? (glob (conc runpath "/*"))) ;; (begin ;; (debug:print 1 "Removing run dir " runpath) ;; (system (conc "rmdir -p " runpath))))