summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2022-03-13 23:05:56 +0530
committerArun Isaac2022-03-14 09:22:37 +0530
commit5e21599d86e121785bae5d7f9a90328bba7e2dcc (patch)
treec0c124b2b2cfbcaa0e6a3a41fb51af1c00620aa9
parent480ead5b457e5412b43fa0cbd6278d7d7c38f34f (diff)
downloadtissue-5e21599d86e121785bae5d7f9a90328bba7e2dcc.tar.gz
tissue-5e21599d86e121785bae5d7f9a90328bba7e2dcc.tar.lz
tissue-5e21599d86e121785bae5d7f9a90328bba7e2dcc.zip
tissue: Memoize the issues function.
The issues function is disk intensive and will be frequently used in different parts of the program. Memoize it. * tissue/issue.scm (memoize-thunk): New function. (issues): Memoize.
-rw-r--r--tissue/issue.scm86
1 files changed, 48 insertions, 38 deletions
diff --git a/tissue/issue.scm b/tissue/issue.scm
index b5813cd..8281588 100644
--- a/tissue/issue.scm
+++ b/tissue/issue.scm
@@ -172,41 +172,51 @@ strings, and return them as a list."
"--" file)
result))
-(define (issues)
- "Return a list of all issues, sorted oldest first."
- ;; Get all gemini files except README.gmi and hidden files. Text
- ;; editors tend to create hidden files while editing, and we want to
- ;; avoid them.
- (sort (call-with-input-pipe
- (lambda (port)
- (port-transduce
- (tfilter-map (lambda (file)
- (and (string-suffix? ".gmi" file)
- (not (string=? (basename file) "README.gmi"))
- (not (string-prefix? "." (basename file)))
- (let* ((file-details (file-details file))
- (all-keywords (hashtable-ref file-details 'keywords '())))
- (issue file
- ;; Fallback to filename if title has no alphabetic
- ;; characters.
- (let ((title (hashtable-ref file-details 'title "")))
- (if (string-any char-set:letter title) title file))
- (hashtable-ref file-details 'creator #f)
- (hashtable-ref file-details 'created-date #f)
- (hashtable-ref file-details 'created-relative-date #f)
- (hashtable-ref file-details 'last-updater #f)
- (hashtable-ref file-details 'last-updated-date #f)
- (hashtable-ref file-details 'last-updated-relative-date #f)
- (hashtable-ref file-details 'assigned '())
- ;; "closed" is a special keyword to indicate
- ;; the open/closed status of an issue.
- (delete "closed" all-keywords)
- (not (member "closed" all-keywords))
- (hashtable-ref file-details 'tasks 0)
- (hashtable-ref file-details 'completed-tasks 0)
- (hashtable-ref file-details 'posts #f))))))
- rcons get-line port))
- "git" "ls-files")
- (lambda (issue1 issue2)
- (< (issue-created-date issue1)
- (issue-created-date issue2)))))
+(define (memoize-thunk thunk)
+ "Return a function memoizing THUNK."
+ (let ((result #f))
+ (lambda ()
+ (unless result
+ (set! result (thunk)))
+ result)))
+
+(define issues
+ (memoize-thunk
+ (lambda ()
+ "Return a list of all issues, sorted oldest first."
+ ;; Get all gemini files except README.gmi and hidden files. Text
+ ;; editors tend to create hidden files while editing, and we want to
+ ;; avoid them.
+ (sort (call-with-input-pipe
+ (lambda (port)
+ (port-transduce
+ (tfilter-map (lambda (file)
+ (and (string-suffix? ".gmi" file)
+ (not (string=? (basename file) "README.gmi"))
+ (not (string-prefix? "." (basename file)))
+ (let* ((file-details (file-details file))
+ (all-keywords (hashtable-ref file-details 'keywords '())))
+ (issue file
+ ;; Fallback to filename if title has no alphabetic
+ ;; characters.
+ (let ((title (hashtable-ref file-details 'title "")))
+ (if (string-any char-set:letter title) title file))
+ (hashtable-ref file-details 'creator #f)
+ (hashtable-ref file-details 'created-date #f)
+ (hashtable-ref file-details 'created-relative-date #f)
+ (hashtable-ref file-details 'last-updater #f)
+ (hashtable-ref file-details 'last-updated-date #f)
+ (hashtable-ref file-details 'last-updated-relative-date #f)
+ (hashtable-ref file-details 'assigned '())
+ ;; "closed" is a special keyword to indicate
+ ;; the open/closed status of an issue.
+ (delete "closed" all-keywords)
+ (not (member "closed" all-keywords))
+ (hashtable-ref file-details 'tasks 0)
+ (hashtable-ref file-details 'completed-tasks 0)
+ (hashtable-ref file-details 'posts #f))))))
+ rcons get-line port))
+ "git" "ls-files")
+ (lambda (issue1 issue2)
+ (< (issue-created-date issue1)
+ (issue-created-date issue2)))))))