Skip to content

Commit

Permalink
fix: don't require user hash match for full checksum (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
sroyal-statsig authored Feb 15, 2025
1 parent b2d5dbd commit a93a832
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
18 changes: 12 additions & 6 deletions packages/client-core/src/DataAdapterCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export abstract class DataAdapterCore {
current: string | null,
user?: StatsigUser,
options?: DataAdapterAsyncOptions,
isCacheValidFor204?: boolean,
): Promise<string | null>;

protected abstract _getCacheKey(user?: StatsigUserInternal): string;
Expand All @@ -124,12 +125,17 @@ export abstract class DataAdapterCore {
user: StatsigUserInternal | undefined,
options: DataAdapterAsyncOptions | undefined,
): Promise<DataAdapterResult | null> {
let cachedData: string | null = null;
if (cachedResult && this._isCachedResultValidFor204(cachedResult, user)) {
cachedData = cachedResult.data;
}

const latest = await this._fetchFromNetwork(cachedData, user, options);
const cachedData: string | null = cachedResult?.data ?? null;
const isCacheValidFor204 =
cachedResult != null &&
this._isCachedResultValidFor204(cachedResult, user);

const latest = await this._fetchFromNetwork(
cachedData,
user,
options,
isCacheValidFor204,
);
if (!latest) {
Log.debug('No response returned for latest value');
return null;
Expand Down
7 changes: 5 additions & 2 deletions packages/js-client/src/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default class StatsigNetwork extends NetworkCore {
current: string | null,
priority?: NetworkPriority,
user?: StatsigUser,
isCacheValidFor204?: boolean,
): Promise<string | null> {
const cache = current
? _typedJsonParse<InitializeResponse>(
Expand All @@ -63,9 +64,11 @@ export default class StatsigNetwork extends NetworkCore {
if (cache?.has_updates) {
data = {
...data,
sinceTime: cache.time,
sinceTime: isCacheValidFor204 ? cache.time : 0,
previousDerivedFields:
'derived_fields' in cache ? cache.derived_fields : {},
'derived_fields' in cache && isCacheValidFor204
? cache.derived_fields
: {},
deltasResponseRequested: true,
full_checksum: cache.full_checksum,
};
Expand Down
2 changes: 2 additions & 0 deletions packages/js-client/src/StatsigEvaluationsDataAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ export class StatsigEvaluationsDataAdapter
current: string | null,
user?: StatsigUser,
options?: DataAdapterAsyncOptions,
isCacheValidFor204?: boolean,
): Promise<string | null> {
const result = await this._network?.fetchEvaluations(
this._getSdkKey(),
current,
options?.priority,
user,
isCacheValidFor204,
);
return result ?? null;
}
Expand Down

0 comments on commit a93a832

Please sign in to comment.