Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.

avoid duplicating items when importing store layouts - #36

Merged
itsreverence merged 2 commits into
masterfrom
duplicate-item-fix
May 2, 2026
Merged

avoid duplicating items when importing store layouts#36
itsreverence merged 2 commits into
masterfrom
duplicate-item-fix

Conversation

@itsreverence

Copy link
Copy Markdown
Owner

No description provided.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@greptile-apps

greptile-apps Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR implements name-based (case-insensitive) deduplication across four services to prevent duplicate items when importing store layouts or adding items to grocery lists. It also fixes the importStore deletion order so items and categories are explicitly removed before their parent aisles, and pre-fetches the full items list outside the import loop to address a prior N+1 query regression.

Confidence Score: 5/5

Safe to merge — all changes are consistent, well-scoped deduplication fixes with no new P1 or P0 issues introduced.

No P0 or P1 findings. The deletion order fix in importStore mirrors the already-correct deleteStore method. Name-based deduplication is applied consistently across all four affected services, and the N+1 query regression noted in a prior thread has been addressed by pre-fetching items outside the loop.

No files require special attention.

Important Files Changed

Filename Overview
src/main/java/com/groceryrun/app/services/GroceryListService.java Adds name-based duplicate guard to addItemToGroceryList; rewrites importGroceryList to pre-fetch all items once and deduplicate by name with deterministic lowest-ID selection.
src/main/java/com/groceryrun/app/services/ItemService.java getAllItems now sorts by ID before putIfAbsent to guarantee deterministic canonical item selection when names collide, and filters out null-named items.
src/main/java/com/groceryrun/app/services/RouteService.java Replaces ID-based matching with name-based matching using a HashSet<String> for O(1) deduplication; unmatched-item detection updated consistently.
src/main/java/com/groceryrun/app/services/StoreService.java Fixes importStore to explicitly delete items and categories before aisles, matching the deletion order already used in deleteStore.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Add or Import Item] --> B{Item name null?}
    B -- Yes --> C[Skip dedup check]
    B -- No --> D{Name already in list? case-insensitive}
    D -- Yes --> E[Skip / no-op]
    D -- No --> F[Add item to list]

    G[importStore] --> H[Delete items per category]
    H --> I[Delete categories per aisle]
    I --> J[Delete aisles]
    J --> K[Clear store aisles collection]
    K --> L[Re-create aisles, categories, items from DTO]

    M[generateRoute] --> N[Iterate store aisles and categories]
    N --> O{Item name in matchedItemNames Set?}
    O -- No --> P[Add to stop and record name in Set]
    O -- Yes --> Q[Skip duplicate store item]
    N --> R[Unmatched: grocery items whose name not in Set]
Loading

Reviews (2): Last reviewed commit: "address issues in import changes" | Re-trigger Greptile

Comment thread src/main/java/com/groceryrun/app/services/GroceryListService.java
Comment thread src/main/java/com/groceryrun/app/services/ItemService.java
Comment thread src/main/java/com/groceryrun/app/services/GroceryListService.java
@itsreverence
itsreverence merged commit daa1d74 into master May 2, 2026
3 checks passed
@itsreverence
itsreverence deleted the duplicate-item-fix branch May 2, 2026 20:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant