We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如图,如果conversation集合中文档比较多的时候, 如果每次只处理100条数据,将会导致mongo查询条件,"skip":放大文档扫描行数
,"skip":
1.建议处理时通过查询条件lt/gt加limit进行处理,取代skip、 2.加大limit数,减少skip执行次数。
lt/gt
这是其他耗时比较多的地方(mongo慢日志)
The text was updated successfully, but these errors were encountered:
谁帮忙看看这样改没问题吧?处理速度是提上来了
// internal\rpc\conversation\conversation.go func (c *conversationServer) GetConversationsNeedDestructMsgs(ctx context.Context, _ *pbconversation.GetConversationsNeedDestructMsgsReq) (*pbconversation.GetConversationsNeedDestructMsgsResp, error) { num, err := c.conversationDatabase.GetAllConversationIDsNumber(ctx) if err != nil { log.ZError(ctx, "GetAllConversationIDsNumber failed", err) return nil, err } const batchNum = 200 maxPage := (num + batchNum - 1) / batchNum temp := make([]*model.Conversation, 0, batchNum) var curConversationID string for pageNumber := 0; pageNumber < int(maxPage); pageNumber++ { pagination := &sdkws.RequestPagination{ PageNumber: 0, ShowNumber: batchNum, } conversationIDs, err := c.conversationDatabase.GetConversationIDsGtID(ctx, curConversationID, pagination) if err != nil { // log.ZError(ctx, "PageConversationIDs failed", err, "pageNumber", pageNumber) continue } // log.ZDebug(ctx, "PageConversationIDs success", "pageNumber", pageNumber, "conversationIDsNum", len(conversationIDs), "conversationIDs", conversationIDs) if len(conversationIDs) == 0 { break } conversations, err := c.conversationDatabase.GetConversationsByConversationID(ctx, conversationIDs) if err != nil { log.ZError(ctx, "GetConversationsByConversationID failed", err, "conversationIDs", conversationIDs) continue } for _, conversation := range conversations { if conversation.IsMsgDestruct && conversation.MsgDestructTime != 0 && ((time.Now().UnixMilli() > (conversation.MsgDestructTime + conversation.LatestMsgDestructTime.UnixMilli() + 8*60*60)) || // 8*60*60 is UTC+8 conversation.LatestMsgDestructTime.IsZero()) { temp = append(temp, conversation) } curConversationID = conversation.ConversationID } } return &pbconversation.GetConversationsNeedDestructMsgsResp{Conversations: convert.ConversationsDB2Pb(temp)}, nil }
// pkg\common\storage\database\mgo\conversation.go func (c *ConversationMgo) GetConversationIDsGtID(ctx context.Context, fromConversationID string, pagination pagination.Pagination) (conversationIDs []string, err error) { var filter bson.M if fromConversationID != "" { filter = bson.M{"conversation_id": bson.M{"$gt": fromConversationID}} } return mongoutil.FindPageOnly[string](ctx, c.coll, filter, pagination, options.Find().SetSort("conversation_id").SetProjection(bson.M{"conversation_id": 1})) }
Sorry, something went wrong.
FGadvancer
No branches or pull requests
Why this feature?
如图,如果conversation集合中文档比较多的时候, 如果每次只处理100条数据,将会导致mongo查询条件
,"skip":
放大文档扫描行数Suggested Solution
1.建议处理时通过查询条件
lt/gt
加limit进行处理,取代skip、2.加大limit数,减少skip执行次数。
Additional Information
这是其他耗时比较多的地方(mongo慢日志)
The text was updated successfully, but these errors were encountered: