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

Projectors refactor #1624

Merged
merged 11 commits into from
Jul 13, 2023
Merged

Projectors refactor #1624

merged 11 commits into from
Jul 13, 2023

Conversation

CDimonaco
Copy link
Member

Description

This pr refactor the usage of projectors, using the changesets with the current entity as the base entity for the changes.

Removes the queries from after_update callbacks, only the necessary association preloads for broadcasts are present.

How was this tested?

Automated tests

@CDimonaco CDimonaco added the elixir Pull requests that update Elixir code label Jul 12, 2023
@CDimonaco CDimonaco self-assigned this Jul 12, 2023
Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

@CDimonaco I still see some Repo.queries in the after_updates that shouldn't be there:

  • Cluster projection, ClusterDeregistered event. This is the unique real change i ask you XD
  • Host projection, HostAddedToCluster, you could add the returning: true value to the insert, so you get the data from the database, and you don't need to query in the after_update. Anyway insert first query later is accepted as a good solution as well.
    Ref

@@ -63,8 +63,10 @@ defmodule Trento.ClusterProjector do
deregistered_at: deregistered_at
},
fn multi ->
cluster = Repo.get!(ClusterReadModel, cluster_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just as a comment, in other project functions, we have this pipelined:

changeset =
    ClusterReadModel
    |> Repo.get!(cluster_id)
    |> ClusterReadModel.changeset(%{
         deregistered_at: deregistered_at
    })

Just in case if you prefer it 😝

Copy link
Member Author

Choose a reason for hiding this comment

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

You triggered my ocd 👁️

Everything refactored to this style

@arbulu89
Copy link
Contributor

@CDimonaco Besides the review, can you make me a small favor? XD
Could you change the line 286 in HostProjector and update Trento.HostReadModel by simply HostReadModel?

Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

💯

@CDimonaco
Copy link
Member Author

Everything done!

@CDimonaco CDimonaco requested a review from arbulu89 July 13, 2023 12:19
Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

💯 🥇

@CDimonaco CDimonaco merged commit e59a5bf into main Jul 13, 2023
16 checks passed
@CDimonaco CDimonaco deleted the projector_refactor branch July 13, 2023 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
elixir Pull requests that update Elixir code
Development

Successfully merging this pull request may close these issues.

3 participants