Refactor search analytics#2
Open
CahidArda wants to merge 4 commits into
Open
Conversation
Replace @upstash/core-analytics with a direct Redis Search implementation. - Store each citation as a hash per (dimensions, hour) at <prefix>:event:<data-hash>:<hourInt>; a Lua script HINCRBYs the counter and writes metadata + TTL (default 28d, configurable) on first hit. - Order-independent data-hash; hourInt kept internal (public API uses Date). - Add AgentAnalytics.query namespace (aggregateBy, timeseries, getIndex, dropIndex) backed by a search index over the event hashes. - Make keyPrefix/eventKey protected. - Move implementation under src/; trim public surface to AgentAnalytics + types. - Add unit + live integration tests.
aggregateBy/timeseries no longer call waitIndexing implicitly; callers invoke query.waitIndexing() when they need read-after-write consistency.
…sing aggregateBy/timeseries now query via redis.search.index (a local handle, no round-trip) instead of createIndex, so each read is a single request. The index must be created once via query.getIndex(); querying a missing index now throws a clear IndexNotFoundError (a describe() round-trip is paid only on the error path) instead of an opaque TypeError.
- aggregateBy({ field, since, until? }) and timeseries({ since, until?, groupBy? })
now each take one options object (AggregateByOptions / TimeseriesOptions).
- Add scripts/seed.ts (bun run seed): writes 30 days of hourly history with
diurnal/weekly patterns and deliberate empty buckets, then creates the index.
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.
No description provided.