From c3181450977fbe17068b433c098662cbde32cdab Mon Sep 17 00:00:00 2001 From: Alexander Suhoverhov Date: Thu, 26 Sep 2013 18:30:14 +0400 Subject: [PATCH] Implement ensure-index properly --- driver/collection.lisp | 1 + driver/indexes.lisp | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/driver/collection.lisp b/driver/collection.lisp index 13ab7ed..7d19f54 100644 --- a/driver/collection.lisp +++ b/driver/collection.lisp @@ -10,6 +10,7 @@ (defclass collection () ((database :initarg :database :reader collection-database) (name :initarg :name :reader collection-name) + (indexes :initform nil :accessor collection-indexes) (fullname :reader fullname))) (defun collection (database name) diff --git a/driver/indexes.lisp b/driver/indexes.lisp index 63964f4..3201cee 100644 --- a/driver/indexes.lisp +++ b/driver/indexes.lisp @@ -21,13 +21,17 @@ (setf (gethash "key" index) keys (gethash "ns" index) (fullname collection) (gethash "name" index) (gethash "name" index name)) + (pushnew name (collection-indexes collection) :test #'equal) (insert-op index-collection index))) (defun ensure-index (collection keys &optional (options (son))) - ;; Should be cached - (create-index collection keys options)) + (unless (find (make-name keys) + (collection-indexes collection) + :test #'equal) + (create-index collection keys options))) (defun drop-indexes (collection &optional (name "*")) + (setf (collection-indexes collection) nil) (let ((cmd (son "dropIndexes" (collection-name collection) "index" name))) (maybe-finished