Made the last scan step (checking for removed files) faster on big libraries

This commit is contained in:
emeric
2024-03-14 23:21:30 +01:00
parent 071b86602e
commit 03425f3c94
4 changed files with 104 additions and 34 deletions
+26
View File
@@ -228,6 +228,32 @@ namespace lms::db
.resultValue();
}
void Track::find(Session& session, TrackId& lastRetrievedTrack, std::size_t batchSize, bool& moreResults, const std::function<void(const Track::pointer&)>& func)
{
session.checkReadTransaction();
auto collection{ session.getDboSession().find<Track>()
.orderBy("id")
.where("id > ?").bind(lastRetrievedTrack)
.limit(static_cast<int>(batchSize) + 1)
.resultList() };
moreResults = false;
std::size_t count{};
for (auto itResult{ collection.begin() }; itResult != collection.end(); ++itResult)
{
if (count++ == batchSize)
{
moreResults = true;
break;
}
func(*itResult);
lastRetrievedTrack = (*itResult)->getId();
}
}
bool Track::exists(Session& session, TrackId id)
{
session.checkReadTransaction();