From 1d5bc2fca56b158726626e3e414f4fcf993fc52a Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 26 Apr 2024 12:21:31 +0300 Subject: [fix] modeline: Improve performance Calling (length (gnosis-review-get-due-notes)) causes performance issues, especially on old hardware, we store the value on a variable and update it every 5 minutes or when we finish a review session. --- gnosis.el | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'gnosis.el') diff --git a/gnosis.el b/gnosis.el index 9cd3d3c..cd02b88 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1,4 +1,4 @@ -;;; gnosis.el --- Spaced Repetition System For Note Taking & Self Testing -*- lexical-binding: t; -*- +;;; gnosis.el --- Spaced Repetition System -*- lexical-binding: t; -*- ;; Copyright (C) 2023 Thanos Apollo @@ -1298,7 +1298,8 @@ NOTES: List of note ids" (recursive-edit)) (?q (gnosis-review-commit note-count) (cl-return)))) - finally (gnosis-review-commit note-count)))))) + finally (gnosis-review-commit note-count))) + (setq gnosis-due-notes (length (gnosis-review-get-due-notes)))))) ;; Editing notes @@ -1871,13 +1872,14 @@ DASHBOARD-TYPE: either 'Notes' or 'Decks' to display the respective dashboard." (if gnosis-modeline-mode (progn (add-to-list 'global-mode-string '(:eval - (format " G:%d" (length (gnosis-review-get-due-notes))))) + (format " G:%d" gnosis-due-notes))) (force-mode-line-update)) (setq global-mode-string (seq-remove (lambda (item) (and (listp item) (eq (car item) :eval) (string-prefix-p " G:" (format "%s" (eval (cadr item)))))) global-mode-string)) + (run-at-time "5 min" 300 #'(lambda () (setq gnosis-due-notes (length (gnosis-review-get-due-notes))))) (force-mode-line-update))) (define-derived-mode gnosis-mode special-mode "Gnosis" -- cgit v1.2.3