-
Notifications
You must be signed in to change notification settings - Fork 2
fix: allow replacing stale entries left after crash #6
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughAdds a position-aware duplicate check in Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant UI as Panel(UI)
participant G as gui.lua
participant S as Store
UI->>G: submit apartment(category, descr, pos)
G->>G: find existing by category+descr
alt existing found
G->>G: compare existing.pos with pos
alt positions equal
G->>S: proceed (treat as same apartment)
S-->>G: success
G-->>UI: success/update
else positions differ
G-->>UI: error "duplicate apartment at different position"
end
else no existing
G->>S: create new apartment
S-->>G: success
G-->>UI: success
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
gui.lua (1)
5-7: Consider using Minetest's built-invector.equals().The implementation is correct, but Minetest core provides
vector.equals(pos1, pos2)for position comparison. Using the built-in function would be more idiomatic and maintainable.Apply this diff to use the built-in function:
-local function isEqual(pos1, pos2) - return (pos1.x == pos2.x) and (pos1.y == pos2.y) and (pos1.z == pos2.z) -endThen update line 130:
- if apartment.apartments[category] and apartment.apartments[category][descr] and (not isEqual(apartment.apartments[category][descr].pos, pos)) then + if apartment.apartments[category] and apartment.apartments[category][descr] and (not vector.equals(apartment.apartments[category][descr].pos, pos)) then
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
gui.lua(2 hunks)
🔇 Additional comments (1)
gui.lua (1)
130-136: The code correctly handles stale entry replacement.The concern is unfounded.
apartment.rent()is always called from gui.lua witholdmetadata = nil(line 148), which ensures theapartment.apartments[category][descr]table entry is updated (init.lua line 178). The position-based check correctly prevents duplicates at different positions while allowing same-position reconfiguration, enabling proper stale entry recovery.
Summary by CodeRabbit