Commit 13ae1675 authored by Dave Griffiths's avatar Dave Griffiths
Browse files

syncing fixes - seems to work so far

parent a3c63db9
...@@ -216,7 +216,7 @@ ...@@ -216,7 +216,7 @@
(msg "running spit") (msg "running spit")
(foldl (foldl
(lambda (e r) (lambda (e r)
(msg (car (car e))) ;;(msg (car (car e)))
(debug! (string-append "Sending a " (car (car e)) " to Raspberry Pi")) (debug! (string-append "Sending a " (car (car e)) " to Raspberry Pi"))
(append (append
(list (list
...@@ -310,6 +310,7 @@ ...@@ -310,6 +310,7 @@
"new-entities-req" "new-entities-req"
(string-append url "fn=entity-versions&table=" table) (string-append url "fn=entity-versions&table=" table)
(lambda (data) (lambda (data)
(msg "entity-versions:" data)
(let ((r (foldl (let ((r (foldl
(lambda (i r) (lambda (i r)
(let* ((unique-id (car i)) (let* ((unique-id (car i))
...@@ -321,6 +322,13 @@ ...@@ -321,6 +322,13 @@
db table db table
(get-entity-id db table unique-id))) (get-entity-id db table unique-id)))
#f))) #f)))
(msg "suck check entity old=" old)
(msg "version there" version)
(when exists
(msg "version here" (get-entity-version
db table
(get-entity-id db table unique-id))))
;; if we don't have this entity or the version on the server is newer ;; if we don't have this entity or the version on the server is newer
(if (or (not exists) old) (if (or (not exists) old)
(cons (suck-entity-from-server db table unique-id) r) (cons (suck-entity-from-server db table unique-id) r)
......
...@@ -188,20 +188,19 @@ ...@@ -188,20 +188,19 @@
'())))) ;;(msg "values for" (ktv-key ktv) "are the same (" (ktv-value ktv) "==" s ")"))))) '())))) ;;(msg "values for" (ktv-key ktv) "are the same (" (ktv-value ktv) "==" s ")")))))
;; don't make dirty or update version here ;; don't make dirty or update version here
(define (update-value-from-sync db table entity-id ktv version) (define (update-value-from-sync db table entity-id ktv)
(let ((s (select-first (let ((s (select-first
db (string-append db (string-append
"select value from " table "_value_" (ktv-type ktv) " where entity_id = ? and attribute_id = ?") "select value from " table "_value_" (ktv-type ktv) " where entity_id = ? and attribute_id = ?")
entity-id (ktv-key ktv)))) entity-id (ktv-key ktv))))
(msg "uvfs")
(msg (ktv-value ktv))
(msg s)
(if (null? s) (if (null? s)
(insert-value db table entity-id ktv #t) (insert-value db table entity-id ktv #t)
(begin
(msg "actually updating (fs)" (ktv-key ktv) "to" (ktv-value ktv))
(db-exec (db-exec
db (string-append "update " table "_value_" (ktv-type ktv) db (string-append "update " table "_value_" (ktv-type ktv)
" set value=?, dirty=0, version=? where entity_id = ? and attribute_id = ?") " set value=?, dirty=0, version=? where entity_id = ? and attribute_id = ?")
(ktv-value ktv) entity-id (ktv-key ktv) (ktv-version ktv))))) (ktv-value ktv) (ktv-version ktv) entity-id (ktv-key ktv))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; getting data out ;; getting data out
...@@ -255,7 +254,6 @@ ...@@ -255,7 +254,6 @@
(map (map
(lambda (kt) (lambda (kt)
(let ((vdv (get-value db table entity-id kt))) (let ((vdv (get-value db table entity-id kt)))
(msg vdv)
(if (null? vdv) (if (null? vdv)
(msg "ERROR: get-entity-plain: no value found for " entity-id " " (ktv-key kt)) (msg "ERROR: get-entity-plain: no value found for " entity-id " " (ktv-key kt))
(list (ktv-key kt) (ktv-type kt) (list (ktv-key kt) (ktv-type kt)
...@@ -270,7 +268,6 @@ ...@@ -270,7 +268,6 @@
(else (else
(foldl (foldl
(lambda (kt r) (lambda (kt r)
(msg "kt is" kt)
(let ((vdv (get-value db table entity-id kt))) (let ((vdv (get-value db table entity-id kt)))
(cond (cond
((null? vdv) ((null? vdv)
...@@ -543,11 +540,12 @@ ...@@ -543,11 +540,12 @@
"update " table "_entity set dirty=?, version=version+1 where entity_id = ?") "update " table "_entity set dirty=?, version=version+1 where entity_id = ?")
1 entity-id)) 1 entity-id))
;; set from a sync, so clear dirty - should be anyway
(define (update-entity-version db table entity-id version) (define (update-entity-version db table entity-id version)
(db-exec (db-exec
db (string-append db (string-append
"update " table "_entity set dirty=?, version=? where entity_id = ?") "update " table "_entity set dirty=0, version=? where entity_id = ?")
1 version entity-id)) version entity-id))
(define (update-entity-clean db table unique-id) (define (update-entity-clean db table unique-id)
(msg "cleaning") (msg "cleaning")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment