Open
Conversation
Add related_floor_id/related_hole_id to Message model so notification deletions can be traced back to their source content. When floors are deleted or marked sensitive, or holes are hidden/deleted, associated notifications and message_user records are now cleaned up. Fixes: - Message model now persists RelatedFloorID/RelatedHoleID (previously only on Notification struct, never saved to DB) - SendSensitive correctly sets RelatedFloorID (was incorrectly using RelatedHoleID with a floor ID) - Delete functions accept *gorm.DB for proper transaction support - Explicit message_user cleanup before message deletion (SQLite compatibility, no FK cascade dependency) Closes #171
- TestDeleteFloorCascadeNotification: verifies notifications are removed when a floor is deleted via API - TestDeleteHoleCascadeNotification: verifies notifications are removed when a hole is deleted via API - TestSendSensitiveRelatedFloorID: ensures SendSensitive sets RelatedFloorID (not RelatedHoleID) - TestNotificationRelatedFieldsPersisted: verifies both related fields are correctly persisted to the message table
0c943b8 to
9f03a27
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to cascade-delete notification messages when their related content is removed/hidden (floor deleted, floor deleted due to sensitive flag, hole hidden, hole deleted), by persisting content linkage on message rows and deleting matching messages (and message_user mappings) during content removal.
Changes:
- Add
related_floor_id/related_hole_idfields toMessageand plumb them throughNotification.Send(). - Introduce delete helpers
DeleteMessageByRelatedFloorID/DeleteMessageByRelatedHoleIDand invoke them from floor/hole deletion flows. - Add tests to validate persistence and cascade deletion behavior.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/message_test.go | Adds tests for message persistence of related IDs and cascade deletion scenarios. |
| models/notification.go | Extends Notification with related IDs and writes them into Message on send. |
| models/message.go | Adds persisted RelatedFloorID / RelatedHoleID columns (indexed) to Message. |
| models/floor.go | Sets RelatedFloorID on multiple floor-generated notification constructors. |
| apis/report/apis.go | Sets RelatedFloorID on punishment notification created from a report. |
| apis/penalty/api.go | Sets RelatedFloorID on penalty notifications. |
| apis/message/apis.go | Adds shared deletion helper and exported delete-by-related-ID functions. |
| apis/hole/apis.go | Calls delete-by-related-hole-ID in hole hide/delete endpoints. |
| apis/floor/apis.go | Calls delete-by-related-floor-ID in floor delete and sensitive-delete flows. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
变更说明
RelatedHoleID,通知只保留楼层维度的关联字段RelatedFloorID测试
MODE=test GOCACHE=/tmp/treehole-next-go-cache go test ./tests -run 'TestNotificationRelatedFloorIDPersisted|TestDeleteFloorCascadeNotification|TestHideHoleCascadeNotification|TestForceDeleteHoleCascadeNotification'GOCACHE=/tmp/treehole-next-go-build-cache GOMODCACHE=/tmp/treehole-next-go-mod-cache go vet ./...