Made some small optims when checking if files are removed
This commit is contained in:
@@ -124,6 +124,18 @@ namespace lms::db
|
||||
});
|
||||
}
|
||||
|
||||
void ArtistInfo::findAbsoluteFilePath(Session& session, ArtistInfoId& lastRetrievedId, std::size_t count, const std::function<void(ArtistInfoId artistInfoId, const std::filesystem::path& absoluteFilePath)>& func)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
|
||||
auto query{ session.getDboSession()->query<std::tuple<ArtistInfoId, std::filesystem::path>>("SELECT a_i.id, a_i.absolute_file_path FROM artist_info a_i").orderBy("a_i.id").where("a_i.id > ?").bind(lastRetrievedId).limit(static_cast<int>(count)) };
|
||||
|
||||
utils::forEachQueryResult(query, [&](const auto& res) {
|
||||
func(std::get<0>(res), std::get<1>(res));
|
||||
lastRetrievedId = std::get<0>(res);
|
||||
});
|
||||
}
|
||||
|
||||
Artist::pointer ArtistInfo::getArtist() const
|
||||
{
|
||||
return _artist;
|
||||
|
||||
@@ -77,15 +77,15 @@ namespace lms::db
|
||||
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<Image>>("SELECT i from image i").where("i.absolute_file_path = ?").bind(file));
|
||||
}
|
||||
|
||||
void Image::find(Session& session, ImageId& lastRetrievedImage, std::size_t count, const std::function<void(const Image::pointer&)>& func)
|
||||
void Image::find(Session& session, ImageId& lastRetrievedId, std::size_t count, const std::function<void(const Image::pointer&)>& func)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
|
||||
auto query{ session.getDboSession()->query<Wt::Dbo::ptr<Image>>("SELECT i from image i").orderBy("i.id").where("i.id > ?").bind(lastRetrievedImage).limit(static_cast<int>(count)) };
|
||||
auto query{ session.getDboSession()->query<Wt::Dbo::ptr<Image>>("SELECT i from image i").orderBy("i.id").where("i.id > ?").bind(lastRetrievedId).limit(static_cast<int>(count)) };
|
||||
|
||||
utils::forEachQueryResult(query, [&](const Image::pointer& image) {
|
||||
func(image);
|
||||
lastRetrievedImage = image->getId();
|
||||
lastRetrievedId = image->getId();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -105,6 +105,18 @@ namespace lms::db
|
||||
});
|
||||
}
|
||||
|
||||
void Image::findAbsoluteFilePath(Session& session, ImageId& lastRetrievedId, std::size_t count, const std::function<void(ImageId imageId, const std::filesystem::path& absoluteFilePath)>& func)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
|
||||
auto query{ session.getDboSession()->query<std::tuple<ImageId, std::filesystem::path>>("SELECT i.id,i.absolute_file_path from image i").orderBy("i.id").where("i.id > ?").bind(lastRetrievedId).limit(static_cast<int>(count)) };
|
||||
|
||||
utils::forEachQueryResult(query, [&](const auto& res) {
|
||||
func(std::get<0>(res), std::get<1>(res));
|
||||
lastRetrievedId = std::get<0>(res);
|
||||
});
|
||||
}
|
||||
|
||||
void Image::setAbsoluteFilePath(const std::filesystem::path& p)
|
||||
{
|
||||
assert(p.is_absolute());
|
||||
|
||||
@@ -71,6 +71,18 @@ namespace lms::db
|
||||
});
|
||||
}
|
||||
|
||||
void PlayListFile::findAbsoluteFilePath(Session& session, PlayListFileId& lastRetrievedId, std::size_t count, const std::function<void(PlayListFileId playListFileId, const std::filesystem::path& absoluteFilePath)>& func)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
|
||||
auto query{ session.getDboSession()->query<std::tuple<PlayListFileId, std::filesystem::path>>("SELECT pl_f.id, pl_f.absolute_file_path FROM playlist_file pl_f").orderBy("pl_f.id").where("pl_f.id > ?").bind(lastRetrievedId).limit(static_cast<int>(count)) };
|
||||
|
||||
utils::forEachQueryResult(query, [&](const auto& res) {
|
||||
func(std::get<0>(res), std::get<1>(res));
|
||||
lastRetrievedId = std::get<0>(res);
|
||||
});
|
||||
}
|
||||
|
||||
PlayListFile::pointer PlayListFile::find(Session& session, PlayListFileId id)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
|
||||
@@ -427,4 +427,10 @@ namespace lms::db
|
||||
}
|
||||
LMS_LOG(DB, DEBUG, "Analyzing " << entry << ": done!");
|
||||
}
|
||||
|
||||
void Session::execute(std::string_view query, long long id)
|
||||
{
|
||||
utils::executeCommand(_session, query, id);
|
||||
}
|
||||
|
||||
} // namespace lms::db
|
||||
|
||||
@@ -265,18 +265,30 @@ namespace lms::db
|
||||
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<Track>>("SELECT t from track t").where("t.id = ?").bind(id));
|
||||
}
|
||||
|
||||
void Track::find(Session& session, TrackId& lastRetrievedTrack, std::size_t count, const std::function<void(const Track::pointer&)>& func, MediaLibraryId library)
|
||||
void Track::find(Session& session, TrackId& lastRetrievedId, std::size_t count, const std::function<void(const Track::pointer&)>& func, MediaLibraryId library)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
|
||||
auto query{ session.getDboSession()->query<Wt::Dbo::ptr<Track>>("SELECT t from track t").orderBy("t.id").where("t.id > ?").bind(lastRetrievedTrack).limit(static_cast<int>(count)) };
|
||||
auto query{ session.getDboSession()->query<Wt::Dbo::ptr<Track>>("SELECT t from track t").orderBy("t.id").where("t.id > ?").bind(lastRetrievedId).limit(static_cast<int>(count)) };
|
||||
|
||||
if (library.isValid())
|
||||
query.where("media_library_id = ?").bind(library);
|
||||
|
||||
utils::forEachQueryResult(query, [&](const Track::pointer& track) {
|
||||
func(track);
|
||||
lastRetrievedTrack = track->getId();
|
||||
lastRetrievedId = track->getId();
|
||||
});
|
||||
}
|
||||
|
||||
void Track::findAbsoluteFilePath(Session& session, TrackId& lastRetrievedId, std::size_t count, const std::function<void(TrackId trackId, const std::filesystem::path& absoluteFilePath)>& func)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
|
||||
auto query{ session.getDboSession()->query<std::tuple<TrackId, std::filesystem::path>>("SELECT t.id,t.absolute_file_path from track t").orderBy("t.id").where("t.id > ?").bind(lastRetrievedId).limit(static_cast<int>(count)) };
|
||||
|
||||
utils::forEachQueryResult(query, [&](const auto& res) {
|
||||
func(std::get<0>(res), std::get<1>(res));
|
||||
lastRetrievedId = std::get<0>(res);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,18 @@ namespace lms::db
|
||||
return utils::execRangeQuery<TrackLyricsId>(query, range);
|
||||
}
|
||||
|
||||
void TrackLyrics::findAbsoluteFilePath(Session& session, TrackLyricsId& lastRetrievedId, std::size_t count, const std::function<void(TrackLyricsId trackLyricsId, const std::filesystem::path& absoluteFilePath)>& func)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
|
||||
auto query{ session.getDboSession()->query<std::tuple<TrackLyricsId, std::filesystem::path>>("SELECT t_lrc.id,t_lrc.absolute_file_path from track_lyrics t_lrc").orderBy("t_lrc.id").where("t_lrc.id > ?").bind(lastRetrievedId).limit(static_cast<int>(count)) };
|
||||
|
||||
utils::forEachQueryResult(query, [&](const auto& res) {
|
||||
func(std::get<0>(res), std::get<1>(res));
|
||||
lastRetrievedId = std::get<0>(res);
|
||||
});
|
||||
}
|
||||
|
||||
TrackLyrics::SynchronizedLines TrackLyrics::getSynchronizedLines() const
|
||||
{
|
||||
SynchronizedLines synchronizedLines;
|
||||
|
||||
@@ -175,10 +175,13 @@ namespace lms::db::utils
|
||||
template<typename... Args>
|
||||
void executeCommand(Wt::Dbo::Session& session, std::string_view command, const Args&... args)
|
||||
{
|
||||
LMS_SCOPED_TRACE_DETAILED_WITH_ARG("Database", "ExecuteCommand", "Command", command);
|
||||
|
||||
Wt::Dbo::Call call{ session.execute(std::string{ command }) };
|
||||
(call.bind(args), ...);
|
||||
|
||||
{
|
||||
LMS_SCOPED_TRACE_DETAILED_WITH_ARG("Database", "ExecuteCommand", "Command", command);
|
||||
call.run();
|
||||
}
|
||||
}
|
||||
|
||||
Wt::WDateTime normalizeDateTime(const Wt::WDateTime& dateTime);
|
||||
|
||||
Reference in New Issue
Block a user