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

tweak: make use of status field in detour list queries #2961

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bfauble
Copy link
Contributor

@bfauble bfauble commented Feb 11, 2025

@bfauble bfauble marked this pull request as ready for review February 11, 2025 22:09
@bfauble bfauble requested a review from a team as a code owner February 11, 2025 22:09
@bfauble bfauble requested review from firestack and removed request for a team February 11, 2025 22:09
Comment on lines 70 to 75
%{
active: Map.get(detours, :active, []),
draft:
detours
|> Map.get(:draft, [])
|> Enum.filter(fn detour -> detour.author_id == user_id end),
past: Map.get(detours, :past, [])
active: detours_for_user(user_id, :active),
draft: detours_for_user(user_id, :draft),
past: detours_for_user(user_id, :past)
}
end
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: since this is only used in the detours controller, how do you feel about pushing this implementation into the detours controller so we're not having to concern ourselves with keeping this interface available at this level?

@@ -162,6 +162,7 @@ defmodule Skate.Detours.Db.Detour do
:author_id,
:activated_at,
:updated_at,
:status,
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: can we remove :state_value with the addition of this?

Copy link
Member

Choose a reason for hiding this comment

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

I'd like to see if we can do this but otherwise approved!

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 believe so. From what I can tell we weren't making use of that field specifically that I can see

Copy link
Member

Choose a reason for hiding this comment

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

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 right, I left that comment after I changed that function to make use of the status field

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so I think the state_value removal may be a bit more complicated than it appears at first glance. we use that function to get the implicit status value in both directions, to and from the db, so during the “activate” action, the db record would have a status of :draft, but the snapshot being passed via upsert_snapshot has the :active %{"value" => %{"Detour Drawing" => %{"Active" => _}}} value. So my inclination is to make sure it’s not being used when pulling detours from the database as it’s no longer necessary and update the categorize_detour function to handle the status -> new_status transition that may be occurring

Comment on lines +85 to +90
defp apply_user_and_status_filter(query, user_id, :draft) do
where(query, [detour: d], d.status == :draft and d.author_id == ^user_id)
end

defp apply_user_and_status_filter(query, _user_id, status) do
where(query, [detour: d], d.status == ^status)
Copy link
Member

Choose a reason for hiding this comment

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

thought(non-blocking): what do you think of putting these in Skate.Detours.Db.Detour.Queries? I'm not that well versed in Elixir, so I'll defer to you here, but my thinking is that query building functions would belong in the Queries module.

@@ -162,6 +162,7 @@ defmodule Skate.Detours.Db.Detour do
:author_id,
:activated_at,
:updated_at,
:status,
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to see if we can do this but otherwise approved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants