From 0a8443d30dde0b7ba914a742182a1900baae2836 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 11 Nov 2012 16:31:17 +0000 Subject: Refactor domain maintenance code. --- background_scripts/completion.coffee | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index c12c6d80..95c50baf 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -200,29 +200,19 @@ class DomainCompleter populateDomains: (onComplete) -> HistoryCache.use (history) => @domains = {} - history.forEach (entry) => - # We want each key in our domains hash to point to the most recent History entry for that domain. - domain = @parseDomain(entry.url) - if domain - previousEntry = @domains[domain] - if previousEntry - previousEntry.entry = entry if previousEntry.lastVisitTime < entry.lastVisitTime - previousEntry.referenceCount +=1 - else - @domains[domain] = { entry: entry, referenceCount: 1 } + history.forEach (entry) => @onPageVisited entry chrome.history.onVisited.addListener(@onPageVisited.bind(this)) chrome.history.onVisitRemoved.addListener(@onVisitRemoved.bind(this)) onComplete() + # We want each key in our domains hash to point to the most recent History entry for that domain. onPageVisited: (newPage) -> domain = @parseDomain(newPage.url) if domain - previousEntry = @domains[domain] - if previousEntry - previousEntry.entry = newPage - previousEntry.referenceCount += 1 - else - @domains[domain] = { entry: newPage, referenceCount: 1 } + @domains[domain] ||= { entry: newPage, referenceCount: 0 } + slot = @domains[domain] + slot.entry = newPage if slot.entry.lastVisitTime < newPage.lastVisitTime + slot.referenceCount += 1 onVisitRemoved: (toRemove) -> if toRemove.allHistory -- cgit v1.2.3