From ddb6d5b3ff405e01b5ad9c8f7af97d1749c67e15 Mon Sep 17 00:00:00 2001 From: kimory Date: Sun, 16 Oct 2022 11:39:19 +0200 Subject: [PATCH] object update: update the indexes --- src/dodb.cl | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/dodb.cl b/src/dodb.cl index 461c642..39eac35 100644 --- a/src/dodb.cl +++ b/src/dodb.cl @@ -106,17 +106,20 @@ :hard nil) )) -;(defun db/index/update (database index-name object file-name old-object) -; (let* ((struct-name (db-struct-name database)) -; (new-value (get-object-attribute struct-name index-name object)) -; (old-value (get-object-attribute struct-name index-name old-object)) -; (symlink-path (db/index/get-symlink-path database index-name object))) -; (if (not (equal new-value old-value)) -; ()))) - (defun db/index/del (database index-name object) (delete-file (db/index/get-symlink-path database index-name object))) +(defun db/index/update (database index-name object file-name old-object) + (let* ((struct-name (db-struct-name database)) + (new-value (get-object-attribute struct-name index-name object)) + (old-value (get-object-attribute struct-name index-name old-object))) + (if (not (equal new-value old-value)) + (progn + ; delete old index + (db/index/del database index-name old-object) + ; create new index + (db/index/new database index-name object file-name))))) + ; Example: database "color" object ; -> "./storage/cars/partitions/by_color/Red/0000000015". (defun db/partition/get-symlink-path (database partition-name object file-name) @@ -263,7 +266,7 @@ ; TODO: locking (defun db/update (database object-index) (let* ((object (gethash object-index (db-data database))) - (file-basename (db/add/new-data-basename database)) + (file-basename (number->filename object-index)) (file-path (get-filepath database file-basename)) (old-object (util:read-object-from-file file-path)) (tmp-file-basename (concatenate 'string file-basename "_tmp")) @@ -272,14 +275,14 @@ ; write object to temporary file (util:write-object-to-file object tmp-file-path) - ; TODO: either remove the file or read the documentation on rename-file + (delete-file file-path) ; rename the temporary file (rename-file tmp-file-path file-basename) ; handle indexes -; (loop for index in (db-indexes database) -; do (db/index/update database index object file-basename old-object)) + (loop for index in (db-indexes database) + do (db/index/update database index object file-basename old-object)) ) ) @@ -293,7 +296,9 @@ (defstruct vehicle name color) -(defparameter cars (db/new "vehicle" "./storage/cars/")) +;(defparameter cars (db/new "vehicle" "./storage/cars/")) +; to launch the tests in RAM +(defparameter cars (db/new "vehicle" "/tmp/storage/cars/")) (db/add cars (make-vehicle :name "Corvet" :color "Red")) (db/add cars (make-vehicle :name "Ferrari" :color "Red"))