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

sort by traffic #846

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions blocks/matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ const matcherBlock: Block<
result ??= matcherFunc(ctx);
} else {
hasher.hash(uniqueId);
const cookieName = `${DECO_MATCHER_PREFIX}${hasher.result()}`;
const cookieName = `${DECO_MATCHER_PREFIX}${hasher.result()}_${($live as {traffic: number})?.traffic}`;
hasher.reset();
const isMatchFromCookie = cookieValue.boolean(
getCookies(ctx.request.headers)[cookieName],
);
result ??= isMatchFromCookie ?? matcherFunc(ctx);
if (result !== isMatchFromCookie) {
const date = new Date();
date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000)); // 1 month
date.setTime(date.getTime() + (5 * 24 * 60 * 60 * 1000)); // 5 days
setCookie(respHeaders, {
name: cookieName,
value: cookieValue.build(uniqueId, result),
Expand Down
2 changes: 1 addition & 1 deletion runtime/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export const middlewareFor = <TAppManifest extends AppManifest = AppManifest>(

if (hasFlags && cookieSegment !== value) {
const date = new Date();
date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000)); // 1 month
date.setTime(date.getTime() + (5 * 24 * 60 * 60 * 1000)); // 5 days
setCookie(newHeaders, {
name: DECO_SEGMENT,
value,
Expand Down
Loading