object update: update the indexes

draft
kimory 2022-10-16 11:39:19 +02:00
parent 284e3a951e
commit ddb6d5b3ff
1 changed files with 18 additions and 13 deletions

View File

@ -106,17 +106,20 @@
:hard nil) :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) (defun db/index/del (database index-name object)
(delete-file (db/index/get-symlink-path 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 ; Example: database "color" object
; -> "./storage/cars/partitions/by_color/Red/0000000015". ; -> "./storage/cars/partitions/by_color/Red/0000000015".
(defun db/partition/get-symlink-path (database partition-name object file-name) (defun db/partition/get-symlink-path (database partition-name object file-name)
@ -263,7 +266,7 @@
; TODO: locking ; TODO: locking
(defun db/update (database object-index) (defun db/update (database object-index)
(let* ((object (gethash object-index (db-data database))) (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)) (file-path (get-filepath database file-basename))
(old-object (util:read-object-from-file file-path)) (old-object (util:read-object-from-file file-path))
(tmp-file-basename (concatenate 'string file-basename "_tmp")) (tmp-file-basename (concatenate 'string file-basename "_tmp"))
@ -272,14 +275,14 @@
; write object to temporary file ; write object to temporary file
(util:write-object-to-file object tmp-file-path) (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 the temporary file
(rename-file tmp-file-path file-basename) (rename-file tmp-file-path file-basename)
; handle indexes ; handle indexes
; (loop for index in (db-indexes database) (loop for index in (db-indexes database)
; do (db/index/update database index object file-basename old-object)) do (db/index/update database index object file-basename old-object))
) )
) )
@ -293,7 +296,9 @@
(defstruct vehicle name color) (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 "Corvet" :color "Red"))
(db/add cars (make-vehicle :name "Ferrari" :color "Red")) (db/add cars (make-vehicle :name "Ferrari" :color "Red"))