| 1 | package workspacestate |
| 2 | |
| 3 | import "maps" |
| 4 | |
| 5 | // AdoptedTopicIDs includes durable adoption evidence after purge removes live |
| 6 | // membership and presentation. Display projections retain only this small |
| 7 | // derived index, not the operation journals or their request/content payloads. |
| 8 | func (s State) AdoptedTopicIDs(workspaceID string) map[string]bool { |
| 9 | index := s.adoptedTopics |
| 10 | if index == nil { |
| 11 | index = adoptedTopicIndex(s) |
| 12 | } |
| 13 | return maps.Clone(index[workspaceID]) |
| 14 | } |
| 15 | |
| 16 | func adoptedTopicIndex(state State) map[string]map[string]bool { |
| 17 | index := map[string]map[string]bool{} |
| 18 | add := func(workspaceID, topicID string) { |
| 19 | if workspaceID == "" || topicID == "" { |
| 20 | return |
| 21 | } |
| 22 | if index[workspaceID] == nil { |
| 23 | index[workspaceID] = map[string]bool{} |
| 24 | } |
| 25 | index[workspaceID][topicID] = true |
| 26 | } |
| 27 | for workspaceID, workspace := range state.Workspaces { |
| 28 | for _, id := range workspace.SessionIDs { |
| 29 | add(workspaceID, state.Presentation[id].TopicID) |
| 30 | } |
| 31 | } |
| 32 | for _, op := range state.PendingOperations { |
| 33 | if op.Phase != "committed" || op.Presentation == nil { |
| 34 | continue |
| 35 | } |
| 36 | if op.Kind == "purge" && len(op.SessionIDs) == 1 && ClassifyPurge(state, op.SessionIDs[0]) == PurgeCommitted { |
| 37 | add(op.WorkspaceID, op.Presentation.TopicID) |
| 38 | continue |
| 39 | } |
| 40 | if op.Mapping == nil { |
| 41 | continue |
| 42 | } |
| 43 | mapping, exists := state.SourceMappings[op.Mapping.SourceKey] |
| 44 | if exists && mapping.WorkspaceID == op.WorkspaceID && mapping.SessionID == op.Mapping.SessionID { |
| 45 | add(mapping.WorkspaceID, op.Presentation.TopicID) |
| 46 | } |
| 47 | } |
| 48 | for _, removal := range state.TopicRemovals { |
| 49 | if removal.Disposition == "archive_sessions" && removal.Phase == "committed" { |
| 50 | add(removal.WorkspaceID, removal.TopicID) |
| 51 | } |
| 52 | } |
| 53 | return index |
| 54 | } |
| 55 |