Open Bug 1844910 Opened 2 years ago Updated 2 years ago

Bookmarks api: expose last visit date

Categories

(WebExtensions :: General, enhancement, P5)

Firefox 115
enhancement

Tracking

(Not tracked)

People

(Reporter: mprops, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0

Steps to reproduce:

The only way to sort bookmarks by last visit date (with the extension api) is to use history.getVisits on each bookmark, and that's very slow (I tried).

Expected results:

Bookmark items should have a last visit date property.

The Bugbug bot thinks this bug should belong to the 'Firefox::Bookmarks & History' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Bookmarks & History

Want to add. Or maybe at least a way to "bump" a bookmark if saving it again.

Component: Bookmarks & History → General
Product: Firefox → WebExtensions

What do you mean by slow? Do you have an example (code snippet) + performance profile recorded at https://profiler.firefox.com/ ?

I wouldn't be opposed to adding support for a parameter to limit the results, and then internally optimize the special case of limit-1 if there is evidence that such an optimization would make sense.

Severity: -- → N/A
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(mprops)
Priority: -- → P5

For instance I tried this code that fetches the last visit date for each bookmark item.

This was slow even with a low number of bookmarks like < 50.

By slow I mean something like ~500ms.

I'm guessing with more bookmarks it's worse.

Without the history check it's "instant".

App.get_last_visit_date = async (bookmark) => {
  let visits = await browser.history.getVisits({url: bookmark.url})

  if (visits.length > 0) {
    bookmark.last_visit_date = new Date(visits[0].visitTime)
  }
  else {
    bookmark.last_visit_date = bookmark.dateAdded
  }
}

App.get_bookmarks = async (query = ``) => {
  App.log(`Getting bookmarks`)
  let results = []

  try {
    results = await browser.bookmarks.search({query: query})
  }
  catch (err) {
    App.log(err, `error`)
    return []
  }

  results = results.filter(x => x.type === `bookmark`)

  for (let bookmark of results) {
    await App.get_last_visit_date(bookmark)
  }

  results.sort((a, b) => {
    return a.last_visit_date > b.last_visit_date ? -1 : 1
  })

  App.last_bookmarks_query = query
  return results.slice(0, App.max_items)
}
Flags: needinfo?(mprops)
You need to log in before you can comment on or make changes to this bug.