-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: cache notification template by trigger identifier #3074
Merged
djabarovgeorge
merged 11 commits into
poc-chached-entity
from
cache-notification-template-by-trigger
Mar 30, 2023
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
85384fe
feat: cache notification template by trigger identifier
djabarovgeorge 446b95c
feat: refactor cache functions
djabarovgeorge 00883d0
fix: build
djabarovgeorge b0021cb
feat: refactor cache keys functions
djabarovgeorge 4f22754
feat: add key prefix enums
djabarovgeorge 36b1011
feat: changed notification template cache by id with 2 invalidation
djabarovgeorge fc689d7
fix: refactor and fix potential bugs
djabarovgeorge 48e0b3f
fix: update tests
djabarovgeorge eb6f870
fix: identifier prefix enum to api key
djabarovgeorge b2b93dc
fix: duplication
djabarovgeorge c8e217a
Merge pull request #3079 from novuhq/cache-refactoring
scopsy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ export const queryBuilder = () => { | |
}; | ||
|
||
export const entityBuilder = () => { | ||
return { subscriber, integration, notificationTemplate, user, environmentByApiKey }; | ||
return { subscriber, integration, user, environmentByApiKey }; | ||
}; | ||
|
||
export const buildQueryKey = ({ | ||
|
@@ -121,14 +121,6 @@ const integration = ({ _id, _environmentId }: { _id: string; _environmentId: str | |
identifier: _id, | ||
}); | ||
|
||
const notificationTemplate = ({ _id, _environmentId }: { _id: string; _environmentId: string }): string => | ||
buildCommonKey({ | ||
type: CacheKeyTypeEnum.ENTITY, | ||
keyEntity: CacheKeyPrefixEnum.NOTIFICATION_TEMPLATE, | ||
environmentId: _environmentId, | ||
identifier: _id, | ||
}); | ||
|
||
const user = ({ _id }: { _id: string }): string => | ||
buildKeyById({ | ||
type: CacheKeyTypeEnum.ENTITY, | ||
|
@@ -170,3 +162,76 @@ export const buildKeyById = ({ | |
identifierPrefix?: string; | ||
identifier: string; | ||
}): string => `${type}:${keyEntity}:${identifierPrefix}=${identifier}`; | ||
|
||
export const notificationTemplateQueryKeyBuild = () => { | ||
const cache = ({ | ||
_environmentId, | ||
identifiers, | ||
}: { | ||
_environmentId: string; | ||
identifiers: ({ id: string } & { triggerIdentifier?: string }) | ({ id?: string } & { triggerIdentifier: string }); | ||
}): string => | ||
buildQueryKeyByEnvironment({ | ||
type: CacheKeyTypeEnum.QUERY, | ||
keyEntity: CacheKeyPrefixEnum.NOTIFICATION_TEMPLATE, | ||
environmentId: _environmentId, | ||
query: identifiers as unknown as Record<string, unknown>, | ||
}); | ||
|
||
const invalidate = ({ _environmentId }: { _environmentId: string }): string => | ||
buildKeyByEnvironment({ | ||
type: CacheKeyTypeEnum.QUERY, | ||
keyEntity: CacheKeyPrefixEnum.NOTIFICATION_TEMPLATE, | ||
environmentId: _environmentId, | ||
}); | ||
|
||
return { | ||
cache, | ||
invalidate, | ||
}; | ||
}; | ||
|
||
/* | ||
* const notificationTemplate = ({ _id, _environmentId }: { _id: string; _environmentId: string }): string => | ||
* buildCommonKey({ | ||
* type: CacheKeyTypeEnum.ENTITY, | ||
* keyEntity: CacheKeyPrefixEnum.NOTIFICATION_TEMPLATE, | ||
* environmentId: _environmentId, | ||
* identifier: _id, | ||
* }); | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗑️ |
||
|
||
export const buildQueryKeyByEnvironment = ({ | ||
type, | ||
keyEntity, | ||
environmentIdPrefix = 'e', | ||
environmentId, | ||
query, | ||
}: { | ||
type: CacheKeyTypeEnum; | ||
keyEntity: CacheKeyPrefixEnum; | ||
environmentIdPrefix?: string; | ||
environmentId: string; | ||
query: Record<string, unknown>; | ||
}): string => { | ||
const keyBase = buildKeyByEnvironment({ | ||
type, | ||
keyEntity, | ||
environmentIdPrefix, | ||
environmentId, | ||
}); | ||
|
||
return `${keyBase}:${QUERY_PREFIX}=${JSON.stringify(query)}`; | ||
}; | ||
|
||
export const buildKeyByEnvironment = ({ | ||
type, | ||
keyEntity, | ||
environmentIdPrefix = 'e', | ||
environmentId, | ||
}: { | ||
type: CacheKeyTypeEnum; | ||
keyEntity: CacheKeyPrefixEnum; | ||
environmentIdPrefix?: string; | ||
environmentId: string; | ||
}): string => `${type}:${keyEntity}:${environmentIdPrefix}=${environmentId}`; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been trying to find a way to be able to express mutually exclusive optional properties but I haven't been able to found it. Not sure if something along these lines would be possible but changed to make the other property optional.
microsoft/TypeScript#14094 (comment)