From d699451fd886b189cf9b060514505b3bcfb95c37 Mon Sep 17 00:00:00 2001 From: saturn Date: Thu, 1 Oct 2020 15:53:19 -0500 Subject: [PATCH] Small optimization in call-with-cache-transaction. --- src/lmdb.lisp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lmdb.lisp b/src/lmdb.lisp index c80db77a..e3ccf703 100644 --- a/src/lmdb.lisp +++ b/src/lmdb.lisp @@ -149,12 +149,14 @@ (error "The database '~A' is not defined." db-name))))) (defun call-with-cache-transaction (fn &key read-only) - (let ((env (get-current-environment))) - (unwind-protect - (progn - (wait-on-semaphore (environment-container-semaphore env)) - (call-with-environment-transaction fn (environment-container-environment env) :read-only read-only)) - (signal-semaphore (environment-container-semaphore env))))) + (if lmdb:*transaction* + (funcall fn) + (let ((env (get-current-environment))) + (unwind-protect + (progn + (wait-on-semaphore (environment-container-semaphore env)) + (call-with-environment-transaction fn (environment-container-environment env) :read-only read-only)) + (signal-semaphore (environment-container-semaphore env)))))) (defmacro with-cache-transaction (&body body) `(call-with-cache-transaction (lambda () ,@body))) -- 2.11.4.GIT