Skip to content

Add command-scoped index cache and cancellable HTTP requests - #29

Merged
polymorcodeus merged 2 commits into
mainfrom
cache+context
Sep 9, 2026
Merged

polymorcodeus merged 2 commits into
mainfrom
cache+context

Conversation

@polymorcodeus

Copy link
Copy Markdown
Owner

Summary

SQLite-derived search index moves from a package-level variable into a command-scoped indexCache, and the web scraping path gains explicit context.Context support with a 10-second timeout. This makes the read and network paths explicit, cancellable, and safe for concurrent test runs.

What's new

  • Command-scoped index cache - cmd/book/index.go introduces indexCache, created in Main and closed by a deferred cache.close(). All index-using commands receive *indexCache explicitly.
  • Explicit cache plumbing - shelves, collections, marks, searchMarks, gc, doctor, runIndexRebuild, runIndexSync, and indexStaleFiles now take the cache as a parameter instead of reaching for global state.
  • Context-aware HTTP requests - web.WebsiteTitle and web.LoadWebsite accept a context.Context, and WebsiteTitle builds an http.Client capped at 10 seconds so cancellation and timeouts are always enforced.
  • Propagated command context - book mark add passes its action context into web.LoadWebsite, replacing the previous implicit context.Background() call site.

Behavior changes / guardrails

  • Main owns the single index database connection for the process lifetime; no other code path opens and closes its own connection.
  • The previous package-level index *catalog.Index variable is removed entirely.
  • Concurrent go test runs no longer share mutable index state.
  • The 10-second effective timeout for title fetching is preserved; only cancellation behavior is added.

Testing

  • Updated internal/web/web_test.go to pass context.Background() into WebsiteTitle.
  • Updated cmd/book/actions_test.go to pass a context into addMark.
  • make check runs fmt, vet, lint, and tests; all green.

@polymorcodeus polymorcodeus self-assigned this Sep 9, 2026
@polymorcodeus
polymorcodeus merged commit aff5611 into main Sep 9, 2026
4 checks passed
@polymorcodeus
polymorcodeus deleted the cache+context branch September 9, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant