Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

feat(flags): Extract flag definitions from redis #42

Merged
merged 9 commits into from
May 30, 2024
Merged

Conversation

neilkakkar
Copy link
Contributor

@neilkakkar neilkakkar commented May 10, 2024

towards PostHog/posthog#22131

I'm getting into more business logic territory, so pipeline reviews optional, but I'll always appreciate them :love-hog:

@neilkakkar neilkakkar changed the title feat(flags): Do token validation and extract distinct id feat(flags): Extract flag definitions from redis May 28, 2024
Base automatically changed from token-validation to main May 29, 2024 13:32
@neilkakkar neilkakkar requested review from a team and removed request for a team May 29, 2024 16:54
@neilkakkar neilkakkar marked this pull request as ready for review May 29, 2024 16:55
@neilkakkar neilkakkar requested review from a team May 29, 2024 16:56
@neilkakkar neilkakkar enabled auto-merge (squash) May 30, 2024 10:29
Copy link
Contributor

@xvello xvello left a comment

Choose a reason for hiding this comment

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

a couple of nits, feel free to merge

pub enum OperatorType {
#[serde(rename = "exact")]
Exact,
#[serde(rename = "is_not")]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you should be able to use a toplevel #[serde(rename_all = "snake_case")] here, see https://serde.rs/container-attrs.html
While annotating each field might feel "safer", I think there's a higher risk of errors than getting the machine to do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, some of them bork here, but I guess I can still do it for the majority, thanks, will do!

#[derive(Debug, Deserialize, Serialize)]
pub enum GroupTypeIndex {}

#[derive(Debug, Deserialize, Serialize)]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: do you need these types to be Serialize? It'll slightly increase compilation time, so it's better to only derive as needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, will fix! I was thinking I'd need it for tests, but then I'm building them all via json, so unnecessary 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, addressed all your comments in the next PR :) - and added TODOs for things I'm deferring.

let serialized_flags = client
.get(format!("{TEAM_FLAGS_CACHE_PREFIX}{}", team_id))
.await
.map_err(|e| match e {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you'll have to refactor this into an Into on the third code path ^^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🫣 - I will

assert_eq!(flag.key, "flag1");
assert_eq!(flag.team_id, team.id);
assert_eq!(flag.filters.groups.len(), 1);
assert_eq!(flag.filters.groups[0].properties.as_ref().unwrap().len(), 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I prefer to use .expect("the hypothesis that proved false") instead of .unwrap(), to help with debugging.
I didn't enable the "don't allow unwrap lint" on, but I will someday

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aha, makes sense, will switch to this 👌

@neilkakkar neilkakkar merged commit 63db2a6 into main May 30, 2024
4 checks passed
@neilkakkar neilkakkar deleted the flag-definitions branch May 30, 2024 16:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants