Skip to content

Commit

Permalink
Use a hash table of IDs to avoid registering redundant tweets.
Browse files Browse the repository at this point in the history
* twittering-mode.el (twittering-http-get-default-sentinel): make
a hash table for already retrieved IDs.
(twittering-cache-status-datum): use a hash table of IDs to avoid
registering redundant tweets.
  • Loading branch information
cvmat committed Feb 3, 2010
1 parent e40b532 commit 8f3b991
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Expand Up @@ -6,6 +6,11 @@
(twittering-cache-status-datum): do not register multiple retweets
referring the same tweet.

* twittering-mode.el (twittering-http-get-default-sentinel): make
a hash table for already retrieved IDs.
(twittering-cache-status-datum): use a hash table of IDs to avoid
registering redundant tweets.

2010-02-03 Tadashi MATSUO <tad@mymail.twin.jp>

* twittering-mode.el (twittering-http-get-default-sentinel): sort
Expand Down
34 changes: 19 additions & 15 deletions twittering-mode.el
Expand Up @@ -1506,10 +1506,21 @@ Available keywords:
(("200")
(let* ((reversed-statuses
(twittering-xmltree-to-status body))
(statuses (reverse reversed-statuses)))
(statuses (reverse reversed-statuses))
(id-table (make-hash-table :test 'equal)))
(mapc
(lambda (status)
(let ((id (cdr (assq 'id status)))
(source-id (cdr-safe (assq 'source-id status))))
(puthash id t id-table)
(when source-id
(puthash source-id t id-table))))
twittering-timeline-data)
(setq twittering-new-tweets-count
(count t (mapcar
#'twittering-cache-status-datum
(lambda (status)
(twittering-cache-status-datum status
id-table))
statuses))))
(setq twittering-timeline-data
(sort twittering-timeline-data
Expand Down Expand Up @@ -1646,24 +1657,17 @@ XML tree as list. Return nil when parse failed.
(error "Failure: invalid HTTP response"))
)))

(defun twittering-cache-status-datum (status-datum &optional data-var)
(defun twittering-cache-status-datum (status-datum id-table &optional data-var)
"Cache status datum into data-var(default twittering-timeline-data)
If STATUS-DATUM is already in DATA-VAR, return nil. If not, return t."
If ID of STATUS-DATUM is already in ID-TABLE, return nil. If not, return t."
(if (null data-var)
(setf data-var 'twittering-timeline-data))
(let* ((id (cdr (assq 'id status-datum)))
(source-id (cdr-safe (assq 'source-id status-datum)))
(pred
(if source-id
(lambda (item)
(or (twittering-status-id= id (cdr (assq 'id item)))
(twittering-status-id= source-id (cdr (assq 'id item)))
(twittering-status-id= source-id
(cdr-safe (assq 'source-id item)))))
(lambda (item)
(twittering-status-id= id (cdr (assq 'id item)))))))
(unless (and (symbol-value data-var)
(find-if pred (symbol-value data-var)))
(retrieved
(or (gethash id id-table)
(and source-id (gethash source-id id-table)))))
(unless (and (symbol-value data-var) retrieved)
(if twittering-jojo-mode
(twittering-update-jojo (cdr (assq 'user-screen-name
status-datum))
Expand Down

0 comments on commit 8f3b991

Please sign in to comment.