fix(member-live): guard the composite sort event and apply review cleanup
This commit is contained in:
parent
f2312c24a1
commit
2c8a403cc0
6 changed files with 66 additions and 48 deletions
|
|
@ -100,27 +100,34 @@ Enum.each(1..count, fn i ->
|
|||
)
|
||||
|
||||
# Give the member fee cycles + a round-robin status so the fee-status column is
|
||||
# populated at scale. Only generate when none exist yet (idempotent re-runs).
|
||||
# populated at scale. Cycles are only generated when none exist yet; the status
|
||||
# is (re-)applied on every run so a run interrupted between generation and the
|
||||
# status update still converges (idempotent — the update is a no-op once set).
|
||||
if not is_nil(member.membership_fee_type_id) do
|
||||
member = Ash.load!(member, :membership_fee_cycles, actor: admin_user_with_role)
|
||||
|
||||
if Enum.empty?(member.membership_fee_cycles) do
|
||||
{:ok, cycles, _} =
|
||||
CycleGenerator.generate_cycles_for_member(member.id,
|
||||
skip_lock?: true,
|
||||
actor: admin_user_with_role
|
||||
)
|
||||
cycles =
|
||||
if Enum.empty?(member.membership_fee_cycles) do
|
||||
{:ok, generated, _} =
|
||||
CycleGenerator.generate_cycles_for_member(member.id,
|
||||
skip_lock?: true,
|
||||
actor: admin_user_with_role
|
||||
)
|
||||
|
||||
status = Enum.at(statuses, rem(i, length(statuses)))
|
||||
generated
|
||||
else
|
||||
member.membership_fee_cycles
|
||||
end
|
||||
|
||||
Enum.each(cycles, fn cycle ->
|
||||
if cycle.status != status do
|
||||
cycle
|
||||
|> Ash.Changeset.for_update(:update, %{status: status})
|
||||
|> Ash.update!(actor: admin_user_with_role, domain: Mv.MembershipFees)
|
||||
end
|
||||
end)
|
||||
end
|
||||
status = Enum.at(statuses, rem(i, length(statuses)))
|
||||
|
||||
Enum.each(cycles, fn cycle ->
|
||||
if cycle.status != status do
|
||||
cycle
|
||||
|> Ash.Changeset.for_update(:update, %{status: status})
|
||||
|> Ash.update!(actor: admin_user_with_role, domain: Mv.MembershipFees)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
if rem(i, 50) == 0, do: IO.puts(" … #{i}/#{count}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue