Add command-scoped index cache and cancellable HTTP requests - #29
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SQLite-derived search index moves from a package-level variable into a command-scoped
indexCache, and the web scraping path gains explicitcontext.Contextsupport with a 10-second timeout. This makes the read and network paths explicit, cancellable, and safe for concurrent test runs.What's new
cmd/book/index.gointroducesindexCache, created inMainand closed by a deferredcache.close(). All index-using commands receive*indexCacheexplicitly.shelves,collections,marks,searchMarks,gc,doctor,runIndexRebuild,runIndexSync, andindexStaleFilesnow take the cache as a parameter instead of reaching for global state.web.WebsiteTitleandweb.LoadWebsiteaccept acontext.Context, andWebsiteTitlebuilds anhttp.Clientcapped at 10 seconds so cancellation and timeouts are always enforced.book mark addpasses its action context intoweb.LoadWebsite, replacing the previous implicitcontext.Background()call site.Behavior changes / guardrails
Mainowns the single index database connection for the process lifetime; no other code path opens and closes its own connection.index *catalog.Indexvariable is removed entirely.go testruns no longer share mutable index state.Testing
internal/web/web_test.goto passcontext.Background()intoWebsiteTitle.cmd/book/actions_test.goto pass a context intoaddMark.make checkruns fmt, vet, lint, and tests; all green.