Refining Skip Count Calculation by Filtering Documents with session_id (#26020)

In the previous implementation, `skip_count` was counting all the
documents in the collection. Instead, we want to filter the documents by
`session_id` and calculate `skip_count` by subtracting `history_size`
from the filtered count.

---------

Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
Krishna Kulkarni 2024-09-21 05:10:56 +05:30 committed by GitHub
parent a8b24135a2
commit c6c508ee96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -122,7 +122,11 @@ class MongoDBChatMessageHistory(BaseChatMessageHistory):
cursor = self.collection.find({self.session_id_key: self.session_id})
else:
skip_count = max(
0, self.collection.count_documents({}) - self.history_size
0,
self.collection.count_documents(
{self.session_id_key: self.session_id}
)
- self.history_size,
)
cursor = self.collection.find(
{self.session_id_key: self.session_id}, skip=skip_count