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: sort feature strategies #4218

Merged
merged 1 commit into from
Jul 11, 2023
Merged

feat: sort feature strategies #4218

merged 1 commit into from
Jul 11, 2023

Conversation

kwasniew
Copy link
Contributor

@kwasniew kwasniew commented Jul 11, 2023

About the changes

Feature strategies will be sorted in client features. This is required for the new variant strategies where the order of strategies matters for the variant that will be selected.

Important files

Discussion points

Client toggles cache is updated on event log change. We need to add re-ordering event for the re-order to trigger changes.

I'm wondering if this change could be behind a flag.

@vercel
Copy link

vercel bot commented Jul 11, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Jul 11, 2023 10:10am
unleash-monorepo-frontend ⬜️ Ignored (Inspect) Jul 11, 2023 10:10am

Copy link
Contributor

@andreas-unleash andreas-unleash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

) {
return strategy1.sortOrder - strategy2.sortOrder;
}
return 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel silly saying this but where do items that end up resolving to 0 actually end up in the final list? I'm guessing this is dependent on the JS engine's implementation of the sort? What if we do something like:

strategies.sort((strategy1, strategy2) => {
    const sortOrder1 = typeof strategy1.sortOrder === 'number' ? strategy1.sortOrder : -Infinity;
    const sortOrder2 = typeof strategy2.sortOrder === 'number' ? strategy2.sortOrder : -Infinity;

    return sortOrder1 - sortOrder2;
});

I want to say that's both very explicit and deterministic independent of whatever JS feels like doing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They way I read it is 0 means don't change the order. I'm afraid of arithmetics with Infinity in JS since we'll get NaN soon

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think it's probably okay, from some reading, most modern JS engines should what we expect here. NaN should also behave like a 0 here too.

This is mostly me nitpicking, I think it's probably okay as is

Copy link
Member

@sighphyre sighphyre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a (probably) optional comment but it's not worth blocking the merge if you feel it's okay to ignore so I'm gonna hit approve

@sighphyre
Copy link
Member

I'm wondering if this change could be behind a flag.

Does this need a flag? This should be effectively the same result for all of our SDKs so long as we don't change the actual API response

@kwasniew kwasniew merged commit 2e9bf76 into main Jul 11, 2023
12 checks passed
@kwasniew kwasniew deleted the sort-client-strategies branch July 11, 2023 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants