Skip to content

Commit 0a8443d

Browse files
Refactor domain maintenance code.
1 parent 2071873 commit 0a8443d

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

background_scripts/completion.coffee

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -200,29 +200,19 @@ class DomainCompleter
200200
populateDomains: (onComplete) ->
201201
HistoryCache.use (history) =>
202202
@domains = {}
203-
history.forEach (entry) =>
204-
# We want each key in our domains hash to point to the most recent History entry for that domain.
205-
domain = @parseDomain(entry.url)
206-
if domain
207-
previousEntry = @domains[domain]
208-
if previousEntry
209-
previousEntry.entry = entry if previousEntry.lastVisitTime < entry.lastVisitTime
210-
previousEntry.referenceCount +=1
211-
else
212-
@domains[domain] = { entry: entry, referenceCount: 1 }
203+
history.forEach (entry) => @onPageVisited entry
213204
chrome.history.onVisited.addListener(@onPageVisited.bind(this))
214205
chrome.history.onVisitRemoved.addListener(@onVisitRemoved.bind(this))
215206
onComplete()
216207

208+
# We want each key in our domains hash to point to the most recent History entry for that domain.
217209
onPageVisited: (newPage) ->
218210
domain = @parseDomain(newPage.url)
219211
if domain
220-
previousEntry = @domains[domain]
221-
if previousEntry
222-
previousEntry.entry = newPage
223-
previousEntry.referenceCount += 1
224-
else
225-
@domains[domain] = { entry: newPage, referenceCount: 1 }
212+
@domains[domain] ||= { entry: newPage, referenceCount: 0 }
213+
slot = @domains[domain]
214+
slot.entry = newPage if slot.entry.lastVisitTime < newPage.lastVisitTime
215+
slot.referenceCount += 1
226216

227217
onVisitRemoved: (toRemove) ->
228218
if toRemove.allHistory

0 commit comments

Comments
 (0)