Chronologically ordered Firefox history via dedicated trigger fh#8
Chronologically ordered Firefox history via dedicated trigger fh#8ffpyt wants to merge 12 commits intoalbertlauncher:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a dedicated history-browsing pathway for the Firefox plugin so users can browse history in true recency order (without Albert’s fuzzy-ranking reordering), while keeping the existing f fuzzy search behavior for bookmarks/history indexing.
Changes:
- Added
FirefoxHistoryHandler (GeneratorQueryHandler)triggered byfhto return history inlast_visit_date DESCorder with optionalLIKEfiltering. - Refactored plugin structure so
Pluginowns shared config/state and exposes two independent handlers viaextensions(). - Added
get_recent_history()SQL helper to retrieve non-nulllast_visit_dateentries ordered by recency.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
__init__.py |
Adds get_recent_history, introduces new FirefoxHistoryHandler, and refactors plugin into separate handlers with dedicated triggers. |
README.md |
Documents the new fh trigger for chronological history browsing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Still not tested @ffpyt . Sorry for the delay. Cannot commit time for now. |
|
@ManuelSchneid3r Tested here. Works fine! TL;DR: new handler to display recent history --> |
|
Ah just found that the scan for bookmarks/history ran twice @ManuelSchneid3r I think I need your opinion here: 2 handlers, so theoretically, 2 instances => 2 scans. Unless we can share something between the two? @ffpyt Maybe you have an idea? (I did not dig much here) |
|
@tomsquest Thanks for your testing! You are right that my changes caused the duplicate scan of bookmarks at startup. Basically, the root cause was calling updateIndexItems after instantiation of the FirefoxQueryHandler. @abstractmethod
def updateIndexItems(self):
"""
Updates the index.
Called when the index needs to be updated, i.e. for initialization, on user changes to the
index config (fuzzy, etc…) and probably by the client itself if the items changed. This
function should call ``setIndexItems`` to update the index.
Do not call this method on plugin initialization. It will be called once loaded.
"""With this change my debug log does not show a duplicate scan anymore. Technically, there is still a "duplicate scan" not visible in the log just now: Do you think this shall also be optimized / fixed? |
|
@ffpyt Seems fine on my side. I don't have any duplication whatsoever (1 log line for bookmarks, 1 for history, that's it). So seems good for me! 👏 |
__init__.py
Outdated
| return [] | ||
|
|
||
|
|
||
| def get_recent_history(places_db: Path, search: str = "", limit: int = 50) -> List[Tuple[str, str, str]]: |
There was a problem hiding this comment.
I think 50 is still a number a user would want to browse through sometimes. If you want to save resources, use the generator to materialize the items lazily (see comment below) and fetch some more items from the database. I cant tell which is a good number. If it comes without penalty/runtime cost i'd go for several hundreds.
__init__.py
Outdated
| places_db = self.profile_path / "places.sqlite" | ||
| history = get_recent_history(places_db, search=context.query.strip()) | ||
|
|
||
| yield [ |
There was a problem hiding this comment.
claudes suggestion:
You can use itertools.islice to lazily chunk the generator:
from itertools import islice
history = get_recent_history(places_db, search=context.query.strip())
def make_item(guid, title, url):
return StandardItem(
id=guid,
text=title if title else url,
subtext=url,
icon_factory=lambda: Icon.composed(self.icon_factory(), Icon.grapheme("🕘"), 1.0),
actions=[
Action("open", "Open in Firefox", lambda u=url: openUrl(u)),
Action("copy", "Copy URL", lambda u=url: setClipboardText(u)),
],
)
it = (make_item(guid, title, url) for guid, title, url in history)
while chunk := list(islice(it, 10)):
yield chunkThe key idea: islice(it, 10) consumes at most 10 items from the iterator each time without materializing the whole thing, and the walrus operator (:=) stops the loop once islice returns an empty list.
There was a problem hiding this comment.
Wow, fancy. A double first time encounter for me:
- Generator expressions ( what my mind identified as simply a tuple comprehension)
- A reasonable use case of the walrus operator
Still for me this is quite an exceptional concept I added this as comments to prevent confusion of potentially my future self or another human being.
Done in 32fc474.
Use generator expression and islice as suggested in PR comment. Add info log message for FirefoxHistoryHandler. Add prefix to differentiate between QueryHandler and HistoryHandler.
No observed performance penalty thanks to islice.
Add ordered Firefox history via dedicated
FirefoxHistoryHandlerMotivation
The existing
FirefoxQueryHandlerusesIndexQueryHandlerwhich ranks results by fuzzy match quality. This is great for searching bookmarks & history by name, but makes it impossible to browse history in chronological order — Albert always reorders results by relevance, even for an empty query.Changes
New
FirefoxHistoryHandler(GeneratorQueryHandler)A self-contained handler triggered by
fhthat yields history in recency order on every query. Typing after the trigger filters results by title or URL via a SQLLIKEclause while preserving the ordering. Because it usesGeneratorQueryHandler, Albert displays results exactly as returned without reranking.Refactored
PluginThe plugin now properly separates concerns:
Plugin(PluginInstance)owns shared state and configuration, while query handlers are standalone objects passed shared state at construction time.extensions()returns both handlers, letting Albert dispatch each trigger independently.New
get_recent_history()functionA dedicated SQL query separate from the existing
get_history()(which is preserved unchanged for bookmark/history indexing). It filters out entries wherelast_visit_date IS NULL— avoiding unvisited prefetched or autocomplete URLs polluting the results — and returns rows ordered bylast_visit_date DESCwith an optional search filter and limit.Triggers
fFirefoxQueryHandlerfhFirefoxHistoryHandler