Repository navigation
refactor: codebase cleanup (indexes, helper extraction, misc) - #112
Merged
Merged
Conversation
Add standalone btree indexes on group_members(user_id), huddl_attendees(user_id), and groups(owner_id). Existing composite unique indexes can't serve user-only lookups since user_id is the trailing column, and there was no index at all on groups.owner_id. Declared via custom_indexes on the Ash resources so the migration generator and snapshots stay in sync.
Replace nested if/else with a single cond for readability. Behavior preserved: provided coordinates short-circuit, unchanged attribute is a passthrough, otherwise geocode and apply.
Replace Group.Changes.GeocodeLocation and Huddl.Changes.GeocodeLocation with a single parameterized Huddlz.Geocoding.GeocodeChange that takes the attribute via a `field:` option. Move the associated test alongside the new module.
Replace five copies of `value |> to_string |> String.replace("_", " ")
|> String.capitalize()` with a shared `humanize/1` in CoreComponents.
Left huddl_live.humanize_filter/1 untouched — it title-cases each word
and has different semantics.
Rename member?/organizer?/get_member_count on group_live/show.ex to member_unchecked?/organizer_unchecked?/member_count_unchecked so the policy bypass is visible at every call site. Also drop stale "removed unused functions" comment.
Five LiveViews (huddl new/edit, group new/edit/locations) each rolled their own init/clear/apply logic for the "Select a location" modal assigns. Extract into HuddlzWeb.Live.Helpers.ModalLocationHelpers with init/1, clear/1, and apply_selected/2. Drops ~66 lines of near-identical code and makes future tweaks to the modal's state a single-file change.
Four LiveViews each defined their own process_eager_upload / store_and_create_pending_image / apply_upload_result / cleanup_pending_image, differing only in storage module, resource, and whether a group_id was required. Extract into HuddlzWeb.Live.Helpers.ImageUploadPipeline that takes a config map and two callback lambdas for create-pending and soft-delete, then wire the four LiveViews to the shared pipeline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Seven atomic commits addressing findings from a codebase audit. Each commit keeps
mix precommitgreen (616 tests, credo --strict clean) and was spot-verified against the live dev DB via tidewave.Commits
perf(db): add indexes on user_id / owner_id foreign keys— three missing btree indexes ongroup_members(user_id),huddl_attendees(user_id),groups(owner_id). Existing composite unique indexes couldn't serve user-only lookups (wrong leading column) andgroups.owner_idhad none. Declared viacustom_indexeson the Ash resources.refactor(geocoding): flatten nested if in geocode_if_changed— nestedif/else→ singlecond.refactor(geocoding): consolidate duplicate GeocodeLocation changes— two near-identical modules replaced by one parameterized{Huddlz.Geocoding.GeocodeChange, field: :x}.refactor(components): extract humanize/1 helper— five copies ofvalue |> to_string |> String.replace("_", " ") |> String.capitalizecollapsed into a shared helper.huddl_live.humanize_filter/1left alone (title-cases each word, different semantics).refactor(group_live): rename authorize?: false helpers to _unchecked—member?/organizer?/get_member_count→member_unchecked?/organizer_unchecked?/member_count_uncheckedso policy bypass is visible at every call site.refactor(live): extract shared modal location state helpers— ~66 lines removed across 5 LiveViews (huddl new/edit, group new/edit/locations). NewHuddlzWeb.Live.Helpers.ModalLocationHelperswithinit/1,clear/1,apply_selected/2.refactor(live): extract image upload pipeline— ~57 lines removed across 4 LiveViews. NewHuddlzWeb.Live.Helpers.ImageUploadPipelinetakes a config map + create-pending / soft-delete lambdas.Net: 468 deletions, 876 insertions (most of which are the migration + three Ash snapshot JSON files and new helper modules).
Deferred — needs design input
Three audit findings were intentionally not shipped in this PR:
start_async/handle_asyncacross 4 LiveViews andrender_asyncin ~26 test sites, and is a UX contract change. Worth its own PR + product input.Test plan
mix precommit— 616 tests, 0 failures, credo --strict cleanmix ecto.migrate)pg_indexesAsh.Resource.Info.actions/1humanize/1produces identical output to the old pipeline for every enum value in useModalLocationHelpers.{init,clear,apply_selected}produce expected socket assigns