Skip to content
Browse files

Refactor domain maintenance code.

  • Loading branch information...
1 parent 2071873 commit 0a8443d30dde0b7ba914a742182a1900baae2836 @smblott-github smblott-github committed
Showing with 6 additions and 16 deletions.
  1. +6 −16 background_scripts/completion.coffee
View
22 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

0 comments on commit 0a8443d

Please sign in to comment.
Something went wrong with that request. Please try again.