aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2014-11-15 02:38:22 +0000
committerArtur Malabarba <bruce.connor.am@gmail.com>2014-11-15 02:38:22 +0000
commit884363ac75fe0c5f8e082c31cfeb8632ad85f19e (patch)
treebf397ba63f9df4727f4ee7df0cf610af94a0691b
parent46166a8a16f6e0c92d2cfc676ab7f302355fa2a1 (diff)
Ensure we don't overwrite the cache
-rw-r--r--sx-question.el20
1 files changed, 14 insertions, 6 deletions
diff --git a/sx-question.el b/sx-question.el
index 76f9a67..7debf4f 100644
--- a/sx-question.el
+++ b/sx-question.el
@@ -72,22 +72,24 @@
Each element has the form (SITE . QUESTION-LIST).
And each element in QUESTION-LIST has the form (QUESTION_ID . LAST-VIEWED-DATE).")
+(defun sx-question--ensure-read-list ()
+ "Ensure the `sx-question--user-read-list' has been read from cache."
+ (unless sx-question--user-read-list
+ (setq sx-question--user-read-list
+ (sx-cache-get 'read-questions))))
+
(defun sx-question--read-p (question)
"Non-nil if QUESTION has been read since last updated."
+ (sx-question--ensure-read-list)
(sx-assoc-let question
(let ((ql (cdr (assoc .site sx-question--user-read-list))))
(and ql
(>= (or (cdr (assoc .question_id ql)) 0)
.last_activity_date)))))
-(defun sx-question--accepted-answer-id (question)
- "Return accepted answer in QUESTION, or nil if none."
- (sx-assoc-let question
- (and (integerp .accepted_answer_id)
- .accepted_answer_id)))
-
(defun sx-question--mark-read (question)
"Mark QUESTION as being read, until it is updated again."
+ (sx-question--ensure-read-list)
(sx-assoc-let question
(let ((site-cell (assoc .site sx-question--user-read-list))
(q-cell (cons .question_id .last_activity_date))
@@ -105,6 +107,12 @@ And each element in QUESTION-LIST has the form (QUESTION_ID . LAST-VIEWED-DATE).
;; Save the results.
(sx-cache-set 'read-questions sx-question--user-read-list))
+(defun sx-question--accepted-answer-id (question)
+ "Return accepted answer in QUESTION, or nil if none."
+ (sx-assoc-let question
+ (and (integerp .accepted_answer_id)
+ .accepted_answer_id)))
+
(defun sx-question--< (property x y &optional pred)
"Non-nil if PROPERTY attribute of question X is less than that of Y.
With optional argument predicate, use it instead of `<'."