TotalCost computes the total cost of a session by walking all messages, sub-sessions, and summary items. It does not use the session-level Cost field, which exists only for backward-compatible persistence.
()
| 964 | // sub-sessions, and summary items. It does not use the session-level Cost |
| 965 | // field, which exists only for backward-compatible persistence. |
| 966 | func (s *Session) TotalCost() float64 { |
| 967 | s.mu.RLock() |
| 968 | defer s.mu.RUnlock() |
| 969 | |
| 970 | var cost float64 |
| 971 | for _, item := range s.Messages { |
| 972 | switch { |
| 973 | case item.IsMessage(): |
| 974 | cost += item.Message.Message.Cost |
| 975 | case item.IsSubSession(): |
| 976 | cost += item.SubSession.TotalCost() |
| 977 | } |
| 978 | cost += item.Cost |
| 979 | } |
| 980 | return cost |
| 981 | } |
| 982 | |
| 983 | // OwnCost returns only this session's direct cost: its own messages and |
| 984 | // item-level costs (e.g. compaction). It excludes sub-session costs. |
no test coverage detected