Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/small-panthers-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@flags-sdk/statsig': patch
---

If using an Edge Config adapter, reduce minimum sync delay for config specs from 5000ms->1000ms
10 changes: 5 additions & 5 deletions packages/adapter-statsig/src/edge-runtime-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export async function createEdgeConfigDataAdapter(options: {
* Statsig syncs config specs outside of the request context,
* so we will support it in triggering config spec synchronization in this case.
*/
export const createSyncingHandler = (): null | (() => void) => {
export const createSyncingHandler = (
minSyncDelayMs: number,
): null | (() => void) => {
// Syncing both in Edge Runtime and Node.js for now, as the sync is otherwise
// not working during local development.
//
Expand All @@ -50,17 +52,15 @@ export const createSyncingHandler = (): null | (() => void) => {
// - the broken syncing due to issues in Date.now in Edge Runtime would be irrelevant
//
// if (typeof EdgeRuntime === 'undefined') return null;

const timerInterval = 5_000;
let isSyncingConfigSpecs = false;
let nextConfigSpecSyncTime = Date.now() + timerInterval;
let nextConfigSpecSyncTime = Date.now() + minSyncDelayMs;
return (): void => {
if (Date.now() >= nextConfigSpecSyncTime && !isSyncingConfigSpecs) {
try {
isSyncingConfigSpecs = true;
const sync = Statsig.syncConfigSpecs().finally(() => {
isSyncingConfigSpecs = false;
nextConfigSpecSyncTime = Date.now() + timerInterval;
nextConfigSpecSyncTime = Date.now() + minSyncDelayMs;
});
import('@vercel/functions').then(({ waitUntil }) => {
waitUntil(sync);
Expand Down
3 changes: 2 additions & 1 deletion packages/adapter-statsig/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export function createStatsigAdapter(options: {
return user != null && typeof user === 'object';
};

const syncHandler = createSyncingHandler();
const minSyncDelayMs = options.edgeConfig ? 1_000 : 5_000;
const syncHandler = createSyncingHandler(minSyncDelayMs);

async function predecide(user?: StatsigUser): Promise<StatsigUser> {
await initialize();
Expand Down
Loading