mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-02 20:01:51 +08:00
fix(findings): address Grok review — keep folders mergeable after group reject, re-anchor groups on finding delete, guard stale suggestion list writes
This commit is contained in:
1 parent
00ec84d14e
commit
0c346a7c0a
6 files changed
+132
-18
No files matched your search
@@ -1499,6 +1499,29 @@ INSERT INTO finding_case_suggestion_members(suggestion_id,finding_id)
|
||||
SELECT id,left_id FROM finding_case_suggestions ON CONFLICT DO NOTHING;
|
||||
INSERT INTO finding_case_suggestion_members(suggestion_id,finding_id)
|
||||
SELECT id,right_id FROM finding_case_suggestions ON CONFLICT DO NOTHING;
|
||||
-- left_id/right_id only anchor a group (ON DELETE CASCADE). Before one anchor
|
||||
-- finding is deleted, move the anchors to the two smallest surviving members so
|
||||
-- the rest of a 3+ member group is not cascade-deleted with it.
|
||||
CREATE OR REPLACE FUNCTION finding_case_suggestion_reanchor() RETURNS trigger AS $$
|
||||
DECLARE
|
||||
sid BIGINT;
|
||||
l BIGINT;
|
||||
r BIGINT;
|
||||
BEGIN
|
||||
FOR sid IN SELECT id FROM finding_case_suggestions WHERE left_id=OLD.id OR right_id=OLD.id LOOP
|
||||
SELECT min(sm.finding_id) INTO l FROM finding_case_suggestion_members sm
|
||||
WHERE sm.suggestion_id=sid AND sm.finding_id<>OLD.id AND EXISTS(SELECT 1 FROM findings f WHERE f.id=sm.finding_id);
|
||||
SELECT min(sm.finding_id) INTO r FROM finding_case_suggestion_members sm
|
||||
WHERE sm.suggestion_id=sid AND sm.finding_id>l AND sm.finding_id<>OLD.id AND EXISTS(SELECT 1 FROM findings f WHERE f.id=sm.finding_id);
|
||||
IF r IS NOT NULL THEN
|
||||
UPDATE finding_case_suggestions SET left_id=l,right_id=r WHERE id=sid;
|
||||
END IF;
|
||||
END LOOP;
|
||||
RETURN OLD;
|
||||
END $$ LANGUAGE plpgsql;
|
||||
DROP TRIGGER IF EXISTS trg_finding_case_suggestion_reanchor ON findings;
|
||||
CREATE TRIGGER trg_finding_case_suggestion_reanchor BEFORE DELETE ON findings
|
||||
FOR EACH ROW EXECUTE FUNCTION finding_case_suggestion_reanchor();
|
||||
-- Rejected/detached pairs are a durable human veto, also checked on group unions.
|
||||
CREATE TABLE IF NOT EXISTS finding_case_blocks (
|
||||
left_id BIGINT NOT NULL REFERENCES findings(id) ON DELETE CASCADE,
|
||||
|
||||
Reference in new issue
Block a user