[elephant-cvs] CVS elephant/src/db-clsql

ieslick ieslick at common-lisp.net
Sat Feb 25 20:53:57 UTC 2006


Update of /project/elephant/cvsroot/elephant/src/db-clsql
In directory clnet:/tmp/cvs-serv26146/src/db-clsql

Modified Files:
	sql-controller.lisp 
Log Message:
Fixed indexing bugs and SQL backend secondary index abstraction

--- /project/elephant/cvsroot/elephant/src/db-clsql/sql-controller.lisp	2006/02/22 20:18:51	1.7
+++ /project/elephant/cvsroot/elephant/src/db-clsql/sql-controller.lisp	2006/02/25 20:53:57	1.8
@@ -154,10 +154,12 @@
 ;; This is a slow, DB cycle intensive operation.  It could chunked somehow,
 ;; I think, probably making it 10 times faster.
 		       (when index?
-			 (sql-add-to-clcn (oid index)
-					  secondary-key
-					  k
-					  sc con :insert-only t)
+			 (unless (sql-from-clcn-key-and-value-existsp 
+				  (oid index) secondary-key k con)
+			   (sql-add-to-clcn (oid index)
+					    secondary-key
+					    k
+					    sc con :insert-only t))
 			 )))
 		 bt))))
 	  index)
@@ -175,10 +177,13 @@
 	   (multiple-value-bind (index? secondary-key)
 	       (funcall (key-fn index) index key value)
 	     (when index?
-	       (sql-add-to-clcn (oid index)
-				secondary-key
-				key
-				sc con :insert-only t)
+	       ;; This duplicates values that are already there...
+	       (unless (sql-from-clcn-key-and-value-existsp 
+			(oid index) secondary-key key con)
+		 (sql-add-to-clcn (oid index)
+				  secondary-key
+				  key
+				  sc con :insert-only t))
 	       )))
        indices)
       ;; Now we place the actual value
@@ -475,6 +480,20 @@
 	nil)
     ))
 
+
+(defun sql-from-clcn-key-and-value-existsp (clcn key value con)
+  (assert (integerp clcn))
+  (let* ((kbs (serialize-to-base64-string key))
+	 (vbs (serialize-to-base64-string value))
+	 (tuples (clsql::select [value]
+				:from [keyvalue]
+				:where [and [= [clctn_id] clcn] [= [key] kbs]
+				            [= [value] vbs]]
+				:database con)))
+       (if tuples
+	   t
+	   nil)))
+
 (defun sql-remove-from-root (key sc con)
   (sql-remove-from-clcn 0 key sc con)
   )




More information about the Elephant-cvs mailing list