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

2703 getter setter #2716

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

2703 getter setter #2716

wants to merge 7 commits into from

Conversation

rorymckinley
Copy link
Collaborator

Description

This is the first of a series of PRs to cleanup usage of Snapshot.get_or_create_latest_for. This functionality was widely used to provide coverage as Lightning migrated to snapshots but is now superfluous for many of the use cases as Workflow creation or modification results in Snapshot creation.

As some of this PR includes updating test fixtures that were relying on the or_create functionality, I have used distinct commits to make it more digestible.

#2703

Validation steps

This functionality was superfluous so there will be no outwardly visible change. The best validation is probably to confirm that my logic as to the removal of the 'or_create' portion of the functionality is correct.

AI Usage

Please disclose how you've used AI in this work (it's cool, we just want to know!):

  • Code generation (copilot but not intellisense)
  • Learning or fact checking
  • Strategy / design
  • Optimisation / refactoring
  • Translation / spellchecking / doc gen
  • Other
  • I have not used AI

You can read more details in our Responsible AI Policy

Pre-submission checklist

  • I have performed a self-review of my code.
  • I have implemented and tested all related authorization policies. (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

Copy link

codecov bot commented Nov 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.23%. Comparing base (ca68969) to head (52e65a2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2716   +/-   ##
=======================================
  Coverage   91.22%   91.23%           
=======================================
  Files         333      333           
  Lines       11869    11869           
=======================================
+ Hits        10828    10829    +1     
+ Misses       1041     1040    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rorymckinley rorymckinley marked this pull request as ready for review November 27, 2024 08:48
@rorymckinley rorymckinley requested a review from jyeshe November 27, 2024 08:48
@rorymckinley rorymckinley force-pushed the 2703-getter-setter branch 4 times, most recently from 388536f to 5141bc7 Compare December 4, 2024 05:54
@rorymckinley rorymckinley self-assigned this Dec 4, 2024
Copy link
Member

@jyeshe jyeshe left a comment

Choose a reason for hiding this comment

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

Super clean and nice introduction of with_snapshot on the factory. I am being picky again just about the idiom that brings extra work for the compiler.

{:ok, get_current_query(workflow) |> repo.one()}
end

multi |> Multi.run(name, get_snapshot)
Copy link
Member

Choose a reason for hiding this comment

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

This goes into that single call anti-pattern:

The |> symbol used in the snippet above is the pipe operator: it takes the output from the expression on its left side and passes it as the first argument to the function call on its right side. 

Its purpose is to highlight the data being transformed by a *series of functions*.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jyeshe changed.

Comment on lines 205 to 206
snapshot = Snapshot.get_current_for(attrs[:workflow])
changeset |> put_assoc(:snapshot, snapshot)
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the cleanup and I see the piping following the pattern on the if so for existing code or cases like this we could discuss with Stu later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jyeshe Changed.

@spec include_latest_snapshot(Multi.t(), binary() | :snapshot, Workflow.t()) ::
Multi.t()
def include_latest_snapshot(multi, name \\ :snapshot, workflow) do
get_snapshot = fn repo, _changes ->
Copy link
Member

Choose a reason for hiding this comment

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

a named dynamic function is not common on Multi usage but doesn't hurt much. One reason to avoid specially on specific context would be that while reading we split it into two different things while there is only one meaningful operation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jyeshe Changed.

Copy link
Member

@jyeshe jyeshe left a comment

Choose a reason for hiding this comment

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

Koszy!

@rorymckinley rorymckinley requested a review from stuartc December 10, 2024 12:16
@taylordowns2000 taylordowns2000 requested review from midigofrank and removed request for stuartc December 19, 2024 11:13
Copy link
Collaborator

@midigofrank midigofrank left a comment

Choose a reason for hiding this comment

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

Nicely done 🙌

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

Successfully merging this pull request may close these issues.

3 participants