mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 09:44:21 +01:00
feat(tui): retain cache when cycling between subagent/parent sessions for perf (#1981)
This commit is contained in:
@@ -171,7 +171,11 @@ func (m *messagesComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.showThinkingBlocks = !m.showThinkingBlocks
|
m.showThinkingBlocks = !m.showThinkingBlocks
|
||||||
m.app.State.ShowThinkingBlocks = &m.showThinkingBlocks
|
m.app.State.ShowThinkingBlocks = &m.showThinkingBlocks
|
||||||
return m, tea.Batch(m.renderView(), m.app.SaveState())
|
return m, tea.Batch(m.renderView(), m.app.SaveState())
|
||||||
case app.SessionLoadedMsg, app.SessionClearedMsg:
|
case app.SessionLoadedMsg:
|
||||||
|
m.tail = true
|
||||||
|
m.loading = true
|
||||||
|
return m, m.renderView()
|
||||||
|
case app.SessionClearedMsg:
|
||||||
m.cache.Clear()
|
m.cache.Clear()
|
||||||
m.tail = true
|
m.tail = true
|
||||||
m.loading = true
|
m.loading = true
|
||||||
@@ -183,6 +187,21 @@ func (m *messagesComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return m, m.renderView()
|
return m, m.renderView()
|
||||||
}
|
}
|
||||||
case app.SessionSelectedMsg:
|
case app.SessionSelectedMsg:
|
||||||
|
currentParent := m.app.Session.ParentID
|
||||||
|
if currentParent == "" {
|
||||||
|
currentParent = m.app.Session.ID
|
||||||
|
}
|
||||||
|
|
||||||
|
targetParent := msg.ParentID
|
||||||
|
if targetParent == "" {
|
||||||
|
targetParent = msg.ID
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear cache only if switching between different session families
|
||||||
|
if currentParent != targetParent {
|
||||||
|
m.cache.Clear()
|
||||||
|
}
|
||||||
|
|
||||||
m.viewport.GotoBottom()
|
m.viewport.GotoBottom()
|
||||||
case app.MessageRevertedMsg:
|
case app.MessageRevertedMsg:
|
||||||
if msg.Session.ID == m.app.Session.ID {
|
if msg.Session.ID == m.app.Session.ID {
|
||||||
|
|||||||
@@ -621,6 +621,10 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
case app.SessionSelectedMsg:
|
case app.SessionSelectedMsg:
|
||||||
|
updated, cmd := a.messages.Update(msg)
|
||||||
|
a.messages = updated.(chat.MessagesComponent)
|
||||||
|
cmds = append(cmds, cmd)
|
||||||
|
|
||||||
messages, err := a.app.ListMessages(context.Background(), msg.ID)
|
messages, err := a.app.ListMessages(context.Background(), msg.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Failed to list messages", "error", err.Error())
|
slog.Error("Failed to list messages", "error", err.Error())
|
||||||
@@ -628,7 +632,8 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
a.app.Session = msg
|
a.app.Session = msg
|
||||||
a.app.Messages = messages
|
a.app.Messages = messages
|
||||||
return a, util.CmdHandler(app.SessionLoadedMsg{})
|
cmds = append(cmds, util.CmdHandler(app.SessionLoadedMsg{}))
|
||||||
|
return a, tea.Batch(cmds...)
|
||||||
case app.SessionCreatedMsg:
|
case app.SessionCreatedMsg:
|
||||||
a.app.Session = msg.Session
|
a.app.Session = msg.Session
|
||||||
case dialog.ScrollToMessageMsg:
|
case dialog.ScrollToMessageMsg:
|
||||||
|
|||||||
Reference in New Issue
Block a user