Skip to content

Commit 68266a6

Browse files
committed
refactor: adjust naming slightly
1 parent 7858855 commit 68266a6

File tree

5 files changed

+31
-29
lines changed

5 files changed

+31
-29
lines changed

packages/core/lib/message-deduplication/messageDeduplicationTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ export interface MessageDeduplicationKeyGenerator<MessageType extends object = o
33
}
44

55
export interface MessageDeduplicationStore {
6-
storeCacheKey(key: string, value: string, ttlSeconds: number): Promise<void>
7-
retrieveCacheKey(key: string): Promise<string | null>
6+
storeKey(key: string, value: string, ttlSeconds: number): Promise<void>
7+
retrieveKey(key: string): Promise<string | null>
88
}
99

1010
export type MessageDeduplicationConfig = {

packages/core/lib/queues/AbstractQueueService.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -522,29 +522,31 @@ export abstract class AbstractQueueService<
522522
}
523523
}
524524

525-
/** Retrieves cache key from deduplication store and checks if it exists */
525+
/** Checks for an existence of deduplication key in deduplication store */
526526
protected async isMessageDuplicated(message: MessagePayloadSchemas): Promise<boolean> {
527527
if (!this.messageDeduplicationConfig) {
528528
return false
529529
}
530530

531-
const cacheKey = this.messageDeduplicationConfig.deduplicationKeyGenerator.generate(message)
532-
const retrievedCacheKey =
533-
await this.messageDeduplicationConfig.deduplicationStore.retrieveCacheKey(cacheKey)
531+
const deduplicationKey =
532+
this.messageDeduplicationConfig.deduplicationKeyGenerator.generate(message)
533+
const deduplicationValue =
534+
await this.messageDeduplicationConfig.deduplicationStore.retrieveKey(deduplicationKey)
534535

535-
return retrievedCacheKey !== null
536+
return deduplicationValue !== null
536537
}
537538

538-
/** Stores cache key in deduplication store */
539+
/** Stores deduplication key in deduplication store */
539540
protected async deduplicateMessage(message: MessagePayloadSchemas): Promise<void> {
540541
if (!this.messageDeduplicationConfig) {
541542
return
542543
}
543544

544-
const cacheKey = this.messageDeduplicationConfig.deduplicationKeyGenerator.generate(message)
545+
const deduplicationKey =
546+
this.messageDeduplicationConfig.deduplicationKeyGenerator.generate(message)
545547

546-
await this.messageDeduplicationConfig.deduplicationStore.storeCacheKey(
547-
cacheKey,
548+
await this.messageDeduplicationConfig.deduplicationStore.storeKey(
549+
deduplicationKey,
548550
new Date().toISOString(),
549551
this.messageDeduplicationConfig.deduplicationWindowSeconds,
550552
)

packages/redis-message-deduplication-store/lib/RedisMessageDeduplicationStore.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ export class RedisMessageDeduplicationStore implements MessageDeduplicationStore
2121
this.config = config
2222
}
2323

24-
async storeCacheKey(key: string, value: string, ttlSeconds: number): Promise<void> {
25-
const cacheKey = this.getCacheKeyWithOptionalPrefix(key)
24+
async storeKey(key: string, value: string, ttlSeconds: number): Promise<void> {
25+
const keyWithPrefix = this.getKeyWithOptionalPrefix(key)
2626

27-
await this.redis.set(cacheKey, value, 'EX', ttlSeconds)
27+
await this.redis.set(keyWithPrefix, value, 'EX', ttlSeconds)
2828
}
2929

30-
retrieveCacheKey(key: string): Promise<string | null> {
31-
const cacheKey = this.getCacheKeyWithOptionalPrefix(key)
30+
retrieveKey(key: string): Promise<string | null> {
31+
const keyWithPrefix = this.getKeyWithOptionalPrefix(key)
3232

33-
return this.redis.get(cacheKey)
33+
return this.redis.get(keyWithPrefix)
3434
}
3535

36-
private getCacheKeyWithOptionalPrefix(key: string): string {
36+
private getKeyWithOptionalPrefix(key: string): string {
3737
return this.config?.keyPrefix?.length ? `${this.config.keyPrefix}:${key}` : key
3838
}
3939
}

packages/redis-message-deduplication-store/test/RedisMessageDeduplicationStore.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ describe('RedisMessageDeduplicationStore', () => {
3333
await cleanRedis(redis)
3434
})
3535

36-
describe('storeCacheKey', () => {
37-
it('stores a cache key in Redis with provided value and ttl', async () => {
36+
describe('storeKey', () => {
37+
it('stores a key in Redis with provided value and ttl', async () => {
3838
const key = 'test_key'
3939
const value = 'test_value'
4040
const ttlSeconds = 60
4141

42-
await store.storeCacheKey(key, value, ttlSeconds)
42+
await store.storeKey(key, value, ttlSeconds)
4343

4444
const storedValue = await redis.get(`${KEY_PREFIX}:${key}`)
4545
expect(storedValue).toBe(value)
@@ -49,15 +49,15 @@ describe('RedisMessageDeduplicationStore', () => {
4949
})
5050
})
5151

52-
describe('retrieveCacheKey', () => {
53-
it('retrieves a cache key from Redis', async () => {
52+
describe('retrieveKey', () => {
53+
it('retrieves a key from Redis', async () => {
5454
const key = 'test_key'
5555
const value = 'test_value'
5656
const ttlSeconds = 60
5757

5858
await redis.set(`${KEY_PREFIX}:${key}`, value, 'EX', ttlSeconds)
5959

60-
const retrievedValue = await store.retrieveCacheKey(key)
60+
const retrievedValue = await store.retrieveKey(key)
6161

6262
expect(retrievedValue).toBe(value)
6363
})

packages/sqs/test/publishers/SqsPermissionPublisher.messageDeduplication.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('SqsPermissionPublisher', () => {
5656
await diContainer.dispose()
5757
})
5858

59-
it('writes cache key to redis using provided deduplication function and publishes message', async () => {
59+
it('writes deduplication key to store using provided deduplication function and publishes message', async () => {
6060
const message = {
6161
id: '1',
6262
messageType: 'add',
@@ -69,13 +69,13 @@ describe('SqsPermissionPublisher', () => {
6969
expect(spy.message).toEqual(message)
7070
expect(spy.processingResult).toBe('published')
7171

72-
const cacheKey = await messageDeduplicationStore.retrieveCacheKey(
72+
const deduplicationKey = await messageDeduplicationStore.retrieveKey(
7373
messageDeduplicationKeyGenerator.generate(message),
7474
)
75-
expect(cacheKey).not.toBeNull()
75+
expect(deduplicationKey).not.toBeNull()
7676
})
7777

78-
it('does not publish the same message if cache key already exists', async () => {
78+
it('does not publish the same message if deduplication key already exists', async () => {
7979
const message = {
8080
id: '1',
8181
messageType: 'add',
@@ -101,7 +101,7 @@ describe('SqsPermissionPublisher', () => {
101101
expect(spySecondCall).toBeUndefined()
102102
})
103103

104-
it('publishing messages that produce different cache keys does not affect each other', async () => {
104+
it('publishing messages that produce different deduplication keys does not affect each other', async () => {
105105
const message1 = {
106106
id: '1',
107107
messageType: 'add',

0 commit comments

Comments
 (0)