Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

chore(worker): move refreshAnalyticsCache to worker#64041

Merged
stefanhengl merged 4 commits intomainfrom
sh/admin-analytics
Jul 25, 2024
Merged

chore(worker): move refreshAnalyticsCache to worker#64041
stefanhengl merged 4 commits intomainfrom
sh/admin-analytics

Conversation

@stefanhengl
Copy link
Member

This moves the refreshAnalyticsCache job from frontend to worker

Notes:
the adminanalytics package uses a global cache which made testing awkward. That's why I introduced the store() abstraction to swap the store at test time.

Test plan

  • new unit test

@cla-bot cla-bot bot added the cla-signed label Jul 24, 2024
@github-actions github-actions bot added team/product-platform team/search-platform Issues owned by the search platform team labels Jul 24, 2024
@stefanhengl stefanhengl marked this pull request as ready for review July 24, 2024 14:06
@stefanhengl stefanhengl requested a review from eseliger July 24, 2024 14:06
Comment on lines +15 to +20
func store() redispool.KeyValue {
if MockStore != nil {
return MockStore
}
return redispool.Store
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't have to happen in this PR, but generally I would be a fan if we don't use the global redispool.Store and global mocks around them so much, and instead pass down a redispool.KeyValue explicitly from the worker Routines init functions. That makes testing easier, and makes clearer which service actually has a dependency on redis.

Since this packages lives in /internal/adminanalytics it's not very clear that only frontend and worker need redis, but for example searcher would not for this purpose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I will follow up in a separate PR.

@stefanhengl stefanhengl merged commit 53806cb into main Jul 25, 2024
@stefanhengl stefanhengl deleted the sh/admin-analytics branch July 25, 2024 08:14
stefanhengl added a commit that referenced this pull request Jul 26, 2024
Relates to #64041

This refactors the `adminanalytics` package to set the cache explicitly
instead of implicitly relying on the global `redispool.Store`. The
global store obfuscated the dependency and also made testing a bit
awkward.

Test plan:
- new unit test
- I ran a local instance and checked for panics in the logs from the
worker job that updates the cache on startup.
- Checked that the following GQL query returned results 

```GQL
query {
  site {
    analytics {
      search(dateRange: LAST_MONTH, grouping: WEEKLY) {
        searches {
          nodes {
            date
            count
          }
          summary {
            totalCount
            totalUniqueUsers
            totalRegisteredUsers
          }
        }
      }
    }
  }
}
```
- I deleted the cache and ran the GQL query again and verified that
cache had the following new entries
```
1) "adminanalytics:Search:Searches:LAST_MONTH:WEEKLY:nodes"
2) "adminanalytics:Search:Searches:LAST_MONTH:WEEKLY:summary"
```
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed team/product-platform team/search-platform Issues owned by the search platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants