Skip to content
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 identity responses #819

Conversation

rmi22186
Copy link
Member

Instructions

  1. PR target branch should be against development
  2. PR title name should follow this format: https://github.com/mParticle/mparticle-workflows/blob/main/.github/workflows/pr-title-check.yml
  3. PR branch prefix should follow this format: https://github.com/mParticle/mparticle-workflows/blob/main/.github/workflows/pr-branch-check-name.yml

Summary

We want to cache our identity responses to limit superfluous identity calls. This applies to login and identify for now. In this PR, I leveraged the vault in order to create a new idCache.

The keys for the idCache are a concatenation of the identities being passed to it along with the das. An example value is as follows:

{
    mpid: 'foo',
    responseText: // cached response from the XHR request
    expirationTimestamp: // number - the date being 1 day added to the time the identity call was made
}

When an identify or login call is attempted, the idCache is checked. If it is valid, we simply return the cached information, and do not make an identity call. If the key does not exist, or it has expired, then we fire another identity call, and cache that one.

Testing Plan

  • Was this tested locally? If not, explain why.
    Integration tests. Unit tests.

Reference Issue (For mParticle employees only. Ignore if you are an outside contributor)

src/sdkRuntimeModels.ts Outdated Show resolved Hide resolved
src/sdkRuntimeModels.ts Outdated Show resolved Hide resolved
src/identity-utils.ts Outdated Show resolved Hide resolved
src/identity-utils.ts Show resolved Hide resolved
src/identity-utils.ts Outdated Show resolved Hide resolved
src/identity-utils.ts Show resolved Hide resolved
src/identity-utils.ts Outdated Show resolved Hide resolved
src/identity-utils.ts Outdated Show resolved Hide resolved
src/identity-utils.ts Show resolved Hide resolved
@rmi22186 rmi22186 force-pushed the feat/SQDSDKS-5976-identity-caching-feature-branch branch from 8d955f2 to 8c84e26 Compare January 9, 2024 20:05
@rmi22186 rmi22186 force-pushed the feat/SQDSDKS-5976-identity-caching branch from a19c697 to c8da08b Compare January 10, 2024 22:33
src/identity-utils.ts Outdated Show resolved Hide resolved
src/identity-utils.ts Outdated Show resolved Hide resolved
src/identity.js Outdated Show resolved Hide resolved
src/identity.js Outdated Show resolved Hide resolved
src/sdkRuntimeModels.ts Outdated Show resolved Hide resolved
src/identity-utils.ts Outdated Show resolved Hide resolved
src/identity-utils.ts Outdated Show resolved Hide resolved
src/identity-utils.ts Outdated Show resolved Hide resolved
src/identity-utils.ts Show resolved Hide resolved
src/identity-utils.ts Outdated Show resolved Hide resolved
src/identity-utils.ts Outdated Show resolved Hide resolved
src/identity-utils.ts Outdated Show resolved Hide resolved
test/src/config/constants.ts Outdated Show resolved Hide resolved
src/validators.ts Outdated Show resolved Hide resolved
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions

6.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@rmi22186 rmi22186 merged commit 5a59d66 into feat/SQDSDKS-5976-identity-caching-feature-branch Jan 22, 2024
25 of 28 checks passed
@rmi22186 rmi22186 mentioned this pull request Jan 23, 2024
1 task
@rmi22186 rmi22186 deleted the feat/SQDSDKS-5976-identity-caching branch April 15, 2024 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants