From 21d5498e8d0c53b7cc5d5bb813f830d92223b44c Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Thu, 7 Nov 2024 09:03:06 +0200 Subject: Refactor review-get-due-notes * Create #'gnosis-review-get--due-notes that returns due note ids and due dates * Create #'gnosis-review-get-due-notes that uses the above functions output but only returns due ids * This is done to improve perfomance & to reduce sql query calls --- gnosis.el | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/gnosis.el b/gnosis.el index 6106114..61f58fe 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1469,22 +1469,30 @@ well." (let ((next-rev (gnosis-get 'next-rev 'review-log `(= id ,id)))) (gnosis-past-or-present-p next-rev))) -(defun gnosis-review-get-due-notes () - "Return a list due notes id for current date." - (let* ((old-notes (cl-loop for note in (gnosis-select 'id 'review-log '(and (> n 0) - (= suspend 0)) - t) - when (gnosis-review-is-due-p note) +(defun gnosis-review-get--due-notes () + "Return due note IDs & due dates." + (let* ((old-notes (cl-loop for note in + (gnosis-select '[id next-rev] 'review-log + '(and (> n 0) + (= suspend 0)) + nil) + when (gnosis-past-or-present-p (cadr note)) collect note)) - (new-notes (cl-loop for note in (gnosis-select 'id 'review-log '(and (= n 0) - (= suspend 0)) - t) - when (gnosis-review-is-due-today-p note) + (new-notes (cl-loop for note in + (gnosis-select '[id next-rev] 'review-log + '(and (= n 0) + (= suspend 0)) + nil) + when (gnosis-past-or-present-p (cadr note)) collect note))) (if gnosis-review-new-first (append (cl-subseq new-notes 0 gnosis-new-notes-limit) old-notes) (append old-notes (cl-subseq new-notes 0 gnosis-new-notes-limit))))) +(defun gnosis-review-get-due-notes () + "Return all due note IDs." + (mapcar #'car (gnosis-review-get--due-notes))) + (defun gnosis-review-get-overdue-notes (&optional note-ids) "Return overdue notes for current DATE. -- cgit v1.2.3