mirror of
https://github.com/standardnotes/server
synced 2026-10-22 00:03:36 -04:00
fix(analytics): bitop over analytics time
This commit is contained in:
@@ -36,22 +36,16 @@ describe('RedisAnalyticsStore', () => {
|
||||
|
||||
await createStore().calculateActivityTotalCountOverTime(AnalyticsActivity.EditingItems, Period.Last30Days)
|
||||
|
||||
expect(redisClient.bitop).toHaveBeenCalledTimes(2)
|
||||
expect(redisClient.bitop).toHaveBeenCalledTimes(1)
|
||||
expect(redisClient.bitop).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'AND',
|
||||
'bitmap:action:editing-items:timespan:2022-4-24-iteration-0',
|
||||
'bitmap:action:editing-items:timespan:2022-4-24-2022-4-26',
|
||||
'bitmap:action:editing-items:timespan:2022-4-24',
|
||||
'bitmap:action:editing-items:timespan:2022-4-25',
|
||||
)
|
||||
expect(redisClient.bitop).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
'AND',
|
||||
'bitmap:action:editing-items:timespan:2022-4-24-iteration-1',
|
||||
'bitmap:action:editing-items:timespan:2022-4-24-iteration-0',
|
||||
'bitmap:action:editing-items:timespan:2022-4-26',
|
||||
)
|
||||
expect(redisClient.bitcount).toHaveBeenCalledWith('bitmap:action:editing-items:timespan:2022-4-24-iteration-1')
|
||||
expect(redisClient.bitcount).toHaveBeenCalledWith('bitmap:action:editing-items:timespan:2022-4-24-2022-4-26')
|
||||
})
|
||||
|
||||
it('should calculate total count changes of activities', async () => {
|
||||
|
||||
@@ -14,22 +14,15 @@ export class RedisAnalyticsStore implements AnalyticsStoreInterface {
|
||||
}
|
||||
|
||||
const periodKeys = this.periodKeyGenerator.getDiscretePeriodKeys(Period.Last30Days)
|
||||
let previousPeriodKey = periodKeys[0]
|
||||
let intersectionPeriodKey = null
|
||||
for (let i = 0; i < periodKeys.length - 1; i++) {
|
||||
intersectionPeriodKey = `${periodKeys[0]}-iteration-${i}`
|
||||
await this.redisClient.bitop(
|
||||
'AND',
|
||||
`bitmap:action:${activity}:timespan:${periodKeys[0]}-${periodKeys[periodKeys.length - 1]}`,
|
||||
...periodKeys.map((p) => `bitmap:action:${activity}:timespan:${p}`),
|
||||
)
|
||||
|
||||
await this.redisClient.bitop(
|
||||
'AND',
|
||||
`bitmap:action:${activity}:timespan:${intersectionPeriodKey}`,
|
||||
`bitmap:action:${activity}:timespan:${previousPeriodKey}`,
|
||||
`bitmap:action:${activity}:timespan:${periodKeys[i + 1]}`,
|
||||
)
|
||||
|
||||
previousPeriodKey = intersectionPeriodKey
|
||||
}
|
||||
|
||||
return this.redisClient.bitcount(`bitmap:action:${activity}:timespan:${intersectionPeriodKey}`)
|
||||
return this.redisClient.bitcount(
|
||||
`bitmap:action:${activity}:timespan:${periodKeys[0]}-${periodKeys[periodKeys.length - 1]}`,
|
||||
)
|
||||
}
|
||||
|
||||
async calculateActivityChangesTotalCount(
|
||||
|
||||
Reference in New Issue
Block a user