Skip to content

Commit

Permalink
reduce payload
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Jan 15, 2025
1 parent b511857 commit 7fb4912
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions packages/fern-docs/bundle/src/server/ld-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ export const createLdPredicate = async ({
};
};

// this is an in-memory "singleton" of all LD clients
// TODO: there should be a way to close the clients when the server shuts down
const ldClientMap = new Map<string, ld.LDClient>();

async function fetchInitialFlags(
sdkKey: string,
context: ld.LDContext,
Expand All @@ -148,14 +152,17 @@ async function fetchInitialFlags(
hash: string | undefined;
}> {
try {
const ldClient = ld.init(sdkKey, {
baseUri: options?.baseUrl,
streamUri: options?.streamUrl,
eventsUri: options?.eventsUrl,
stream: false,
sendEvents: false,
diagnosticOptOut: true,
});
const ldClient =
ldClientMap.get(sdkKey) ??
ld.init(sdkKey, {
baseUri: options?.baseUrl,
streamUri: options?.streamUrl,
eventsUri: options?.eventsUrl,
stream: false,
sendEvents: false,
diagnosticOptOut: true,
});
ldClientMap.set(sdkKey, ldClient);
const flags = await ldClient.allFlagsState(context, {
clientSideOnly: true, // these flags will be passed to the client side
detailsOnlyForTrackedFlags: true,
Expand Down

0 comments on commit 7fb4912

Please sign in to comment.