optimize #129 use new goroutine handle log in mieliLogHook fire

pull/130/head
alimy 2 years ago
parent 432885d164
commit 4742138c48

@ -22,11 +22,13 @@ func (h *meiliLogHook) Fire(entry *logrus.Entry) error {
"data": entry.Data,
}}
// 先尝试进log缓存否则直接加文档
// 先尝试进log缓存否则直接新开goroutine加文档
select {
case h.addDocsCh <- &data:
default:
h.index().AddDocuments(data)
go func(index *meilisearch.Index, item meiliLogData) {
index.AddDocuments(item)
}(h.index(), data)
}
return nil

@ -50,12 +50,10 @@ func (s *meiliTweetSearchServant) IndexName() string {
}
func (s *meiliTweetSearchServant) AddDocuments(data core.DocItems, primaryKey ...string) (bool, error) {
task, err := s.index.AddDocuments(data, primaryKey...)
if err != nil {
if _, err := s.index.AddDocuments(data, primaryKey...); err != nil {
logrus.Errorf("meiliTweetSearchServant.AddDocuments error: %v", err)
return false, err
}
logrus.Debugf("meiliTweetSearchServant.AddDocuments task: %+v", task.Details)
return true, nil
}

Loading…
Cancel
Save