store: remove unneeded header callback
The message store keeps a map of callbacks for headers that are being fetched. This is not used anywhere in the code base. Instead of a func(*types.MessageInfo) callback use a general func(types.WorkerMessage) in the worker.PostAction function to make it more useful. This callback allows now to get a feedback when all headers are fetched successfully. Note that the pending header map remains so that the same header is not fetched multiple times. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
cfc19a7ec2
commit
22e6c9e4fa
1 changed files with 7 additions and 19 deletions
|
@ -25,7 +25,6 @@ type MessageStore struct {
|
|||
|
||||
selectedUid uint32
|
||||
bodyCallbacks map[uint32][]func(*types.FullMessage)
|
||||
headerCallbacks map[uint32][]func(*types.MessageInfo)
|
||||
|
||||
// marking
|
||||
marker marker.Marker
|
||||
|
@ -79,7 +78,6 @@ func NewMessageStore(worker *types.Worker,
|
|||
selectedUid: MagicUid,
|
||||
|
||||
bodyCallbacks: make(map[uint32][]func(*types.FullMessage)),
|
||||
headerCallbacks: make(map[uint32][]func(*types.MessageInfo)),
|
||||
|
||||
threadedView: thread,
|
||||
buildThreads: clientThreads,
|
||||
|
@ -99,7 +97,7 @@ func NewMessageStore(worker *types.Worker,
|
|||
}
|
||||
|
||||
func (store *MessageStore) FetchHeaders(uids []uint32,
|
||||
cb func(*types.MessageInfo),
|
||||
cb func(types.WorkerMessage),
|
||||
) {
|
||||
// TODO: this could be optimized by pre-allocating toFetch and trimming it
|
||||
// at the end. In practice we expect to get most messages back in one frame.
|
||||
|
@ -108,13 +106,6 @@ func (store *MessageStore) FetchHeaders(uids []uint32,
|
|||
if _, ok := store.pendingHeaders[uid]; !ok {
|
||||
toFetch = append(toFetch, uid)
|
||||
store.pendingHeaders[uid] = nil
|
||||
if cb != nil {
|
||||
if list, ok := store.headerCallbacks[uid]; ok {
|
||||
store.headerCallbacks[uid] = append(list, cb)
|
||||
} else {
|
||||
store.headerCallbacks[uid] = []func(*types.MessageInfo){cb}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(toFetch) > 0 {
|
||||
|
@ -122,9 +113,11 @@ func (store *MessageStore) FetchHeaders(uids []uint32,
|
|||
if _, ok := msg.(*types.Error); ok {
|
||||
for _, uid := range toFetch {
|
||||
delete(store.pendingHeaders, uid)
|
||||
delete(store.headerCallbacks, uid)
|
||||
}
|
||||
}
|
||||
if cb != nil {
|
||||
cb(msg)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -255,11 +248,6 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
|
|||
}
|
||||
if _, ok := store.pendingHeaders[msg.Info.Uid]; msg.Info.Envelope != nil && ok {
|
||||
delete(store.pendingHeaders, msg.Info.Uid)
|
||||
if cbs, ok := store.headerCallbacks[msg.Info.Uid]; ok {
|
||||
for _, cb := range cbs {
|
||||
cb(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
if store.builder != nil {
|
||||
store.builder.Update(msg.Info)
|
||||
|
|
Loading…
Reference in a new issue