From d93ab7e848bf0f4bc1087504eecd7c959d19bf6c Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Fri, 13 Sep 2024 13:52:38 -0400 Subject: Update :3 --- src/wasp-user.el | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'src/wasp-user.el') diff --git a/src/wasp-user.el b/src/wasp-user.el index 060f9291..d5231ae1 100644 --- a/src/wasp-user.el +++ b/src/wasp-user.el @@ -3,6 +3,7 @@ ;;; Code: (require 's) +(require 'ht) (require 'wasp-utils) (require 'wasp-db) @@ -11,6 +12,31 @@ (defvar w/user-current-name nil) (defvar w/user-current nil) +(defvar w/user-cache (ht-create) + "A read-only cache of user records for the current session.") + +(defun w/user-cache-update (nm d) + "Set the cache entry for user NM to D." + (ht-set! w/user-cache (s-downcase nm) d)) + +(defun w/user-cache-get (nm) + "Get the cache entry for user NM." + (ht-get w/user-cache (s-downcase nm))) + +(defun w/user-cache-populate () + "Populate `w/user-cache' with entries for all users. +\(This is slow, so it happens once at startup.\)" + (ht-clear! w/user-cache) + (w/db-keys + "user:*" + (lambda (users) + (--each users + (let ((nm (cadr (s-split ":" it)))) + (w/user-get + nm + (lambda (_) + (message "Updated cache for %s" nm)))))))) + (defun w/user-db-key (nm) "Return the database key for user NM." (s-concat "user:" (s-downcase nm))) @@ -26,12 +52,15 @@ Pass the resulting Lisp form to K." ((d) (stringp d) (res (w/read-sexp d))) - (funcall k res) + (progn + (w/user-cache-update nm res) + (funcall k res)) (funcall k nil)))))) (defun w/user-set (nm d) "Save the Lisp form D as the user data for NM." (when (and nm (stringp nm) d) + (w/user-cache-update nm d) (w/db-set (w/user-db-key nm) (format "%S" d)))) @@ -52,7 +81,7 @@ Save it back to the database after K returns." (let ((boost (alist-get :boost w/user-current))) (or (and boost (> boost 2)) (and boost (< boost -2)) - (-contains? w/user-whitelist w/user-current-name)))) + (-contains? w/user-whitelist (s-downcase w/user-current-name))))) (defun w/user-boost (user) "Increase USER's boost power by 1." -- cgit v1.2.3