Initial support for multi library, still WIP

This commit is contained in:
emeric
2024-01-25 00:01:11 +01:00
parent f5f577af52
commit 0ed3f1ba79
85 changed files with 3076 additions and 1445 deletions
+5 -1
View File
@@ -46,7 +46,8 @@ namespace Database
|| params.linkType
|| params.track.isValid()
|| params.release.isValid()
|| params.clusters.size() == 1)
|| params.clusters.size() == 1
|| params.mediaLibrary.isValid())
{
query.join("track t ON t.id = t_a_l.track_id");
query.join("track_artist_link t_a_l ON t_a_l.artist_id = a.id");
@@ -120,6 +121,9 @@ namespace Database
if (params.release.isValid())
query.where("t.release_id = ?").bind(params.release);
if (params.mediaLibrary.isValid())
query.where("t.media_library_id = ?").bind(params.mediaLibrary);
switch (params.sortMethod)
{
case ArtistSortMethod::None:
+1
View File
@@ -20,6 +20,7 @@
#include "database/Cluster.hpp"
#include "database/Artist.hpp"
#include "database/MediaLibrary.hpp"
#include "database/Release.hpp"
#include "database/ScanSettings.hpp"
#include "database/Session.hpp"
+21 -22
View File
@@ -26,29 +26,28 @@
namespace Wt::Dbo
{
template<typename T>
struct sql_value_traits<EnumSet<T>, void> : public sql_value_traits<long long>
{
using ValueType = typename EnumSet<T>::ValueType;
static_assert(sizeof(long long) > sizeof(ValueType));
template<typename T>
struct sql_value_traits<EnumSet<T>, void> : public sql_value_traits<long long>
{
using ValueType = typename EnumSet<T>::ValueType;
static_assert(sizeof(long long) > sizeof(ValueType));
static void bind(EnumSet<T> v, SqlStatement* statement, int column, int size)
{
sql_value_traits<long long>::bind(static_cast<long long>(v.getBitfield()), statement, column, size);
}
static void bind(EnumSet<T> v, SqlStatement *statement, int column, int size)
{
sql_value_traits<long long>::bind(static_cast<long long>(v.getBitfield()), statement, column, size);
}
static bool read(EnumSet<T>& v, SqlStatement *statement, int column, int size)
{
long long val;
if (sql_value_traits<long long>::read(val, statement, column, size))
{
v.setBitfield(val);
return true;
}
v.clear();
return false;
}
};
static bool read(EnumSet<T>& v, SqlStatement* statement, int column, int size)
{
long long val;
if (sql_value_traits<long long>::read(val, statement, column, size))
{
v.setBitfield(val);
return true;
}
v.clear();
return false;
}
};
}
+66 -50
View File
@@ -29,19 +29,26 @@ namespace Database
{
namespace
{
Wt::Dbo::Query<ArtistId> createArtistsQuery(Wt::Dbo::Session& session, UserId userId, ScrobblingBackend backend, const std::vector<ClusterId>& clusterIds, std::optional<TrackArtistLinkType> linkType)
Wt::Dbo::Query<ArtistId> createArtistsQuery(Wt::Dbo::Session& session, const Listen::ArtistStatsFindParameters& params)
{
auto query{ session.query<ArtistId>("SELECT a.id from artist a")
.join("track t ON t.id = t_a_l.track_id")
.join("track_artist_link t_a_l ON t_a_l.artist_id = a.id")
.join("listen l ON l.track_id = t.id")
.where("l.user_id = ?").bind(userId)
.where("l.backend = ?").bind(backend) };
.where("l.user_id = ?").bind(params.user) };
if (linkType)
query.where("t_a_l.type = ?").bind(*linkType);
if (params.backend)
query.where("l.backend = ?").bind(*params.backend);
if (!clusterIds.empty())
assert(!params.artist.isValid()); // poor check
if (params.library.isValid())
query.where("t.media_library_id = ?").bind(params.library);
if (params.linkType)
query.where("t_a_l.type = ?").bind(*params.linkType);
if (!params.clusters.empty())
{
std::ostringstream oss;
oss << "a.id IN (SELECT DISTINCT a.id FROM artist a"
@@ -51,14 +58,14 @@ namespace Database
" INNER JOIN track_cluster t_c ON t_c.track_id = t.id";
WhereClause clusterClause;
for (auto id : clusterIds)
for (auto id : params.clusters)
{
clusterClause.Or(WhereClause("c.id = ?"));
query.bind(id);
}
oss << " " << clusterClause.get();
oss << " GROUP BY t.id,a.id HAVING COUNT(DISTINCT c.id) = " << clusterIds.size() << ")";
oss << " GROUP BY t.id,a.id HAVING COUNT(DISTINCT c.id) = " << params.clusters.size() << ")";
query.where(oss.str());
}
@@ -66,15 +73,26 @@ namespace Database
return query;
}
Wt::Dbo::Query<ReleaseId> createReleasesQuery(Wt::Dbo::Session& session, UserId userId, ScrobblingBackend backend, const std::vector<ClusterId>& clusterIds)
Wt::Dbo::Query<ReleaseId> createReleasesQuery(Wt::Dbo::Session& session, const Listen::StatsFindParameters& params)
{
auto query{ session.query<ReleaseId>("SELECT r.id from release r")
.join("track t ON t.release_id = r.id")
.join("listen l ON l.track_id = t.id")
.where("l.user_id = ?").bind(userId)
.where("l.backend = ?").bind(backend) };
.where("l.user_id = ?").bind(params.user) };
if (!clusterIds.empty())
if (params.backend)
query.where("l.backend = ?").bind(*params.backend);
if (params.artist.isValid())
{
query.join("track_artist_link t_a_l ON t_a_l.track_id = t.id")
.where("t_a_l.artist_id = ?").bind(params.artist);
}
if (params.library.isValid())
query.where("t.media_library_id = ?").bind(params.library);
if (!params.clusters.empty())
{
std::ostringstream oss;
oss << "r.id IN (SELECT DISTINCT r.id FROM release r"
@@ -83,14 +101,14 @@ namespace Database
" INNER JOIN track_cluster t_c ON t_c.track_id = t.id";
WhereClause clusterClause;
for (ClusterId id : clusterIds)
for (ClusterId id : params.clusters)
{
clusterClause.Or(WhereClause("c.id = ?"));
query.bind(id);
}
oss << " " << clusterClause.get();
oss << " GROUP BY t.id HAVING COUNT(DISTINCT c.id) = " << clusterIds.size() << ")";
oss << " GROUP BY t.id HAVING COUNT(DISTINCT c.id) = " << params.clusters.size() << ")";
query.where(oss.str());
}
@@ -98,17 +116,25 @@ namespace Database
return query;
}
Wt::Dbo::Query<TrackId> createTracksQuery(Wt::Dbo::Session& session, UserId userId, ArtistId artistId, ScrobblingBackend backend, const std::vector<ClusterId>& clusterIds)
Wt::Dbo::Query<TrackId> createTracksQuery(Wt::Dbo::Session& session, const Listen::StatsFindParameters& params)
{
auto query{ session.query<TrackId>("SELECT t.id from track t")
.join("listen l ON l.track_id = t.id")
.where("l.user_id = ?").bind(userId)
.where("l.backend = ?").bind(backend) };
.where("l.user_id = ?").bind(params.user) };
if (artistId.isValid())
query.join("track_artist_link t_a_l ON t_a_l.track_id = t.id").where("t_a_l.artist_id = ?").bind(artistId);
if (params.backend)
query.where("l.backend = ?").bind(*params.backend);
if (!clusterIds.empty())
if (params.artist.isValid())
{
query.join("track_artist_link t_a_l ON t_a_l.track_id = t.id")
.where("t_a_l.artist_id = ?").bind(params.artist);
}
if (params.library.isValid())
query.where("t.media_library_id = ?").bind(params.library);
if (!params.clusters.empty())
{
std::ostringstream oss;
oss << "t.id IN (SELECT DISTINCT t.id FROM track t"
@@ -116,14 +142,14 @@ namespace Database
" INNER JOIN cluster c ON c.id = t_c.cluster_id";
WhereClause clusterClause;
for (auto id : clusterIds)
for (auto id : params.clusters)
{
clusterClause.Or(WhereClause("c.id = ?")).bind(id.toString());
query.bind(id);
}
oss << " " << clusterClause.get();
oss << " GROUP BY t.id HAVING COUNT(*) = " << clusterIds.size() << ")";
oss << " GROUP BY t.id HAVING COUNT(*) = " << params.clusters.size() << ")";
query.where(oss.str());
}
@@ -188,76 +214,66 @@ namespace Database
.resultValue();
}
RangeResults<ArtistId> Listen::getTopArtists(Session& session, UserId userId, ScrobblingBackend backend, const std::vector<ClusterId>& clusterIds, std::optional<TrackArtistLinkType> linkType, std::optional<Range> range)
RangeResults<ArtistId> Listen::getTopArtists(Session& session, const ArtistStatsFindParameters& params)
{
session.checkReadTransaction();
auto query{ createArtistsQuery(session.getDboSession(), userId, backend, clusterIds, linkType) };
auto query{ createArtistsQuery(session.getDboSession(), params) };
auto collection{ query
.orderBy("COUNT(a.id) DESC")
.groupBy("a.id") };
return Utils::execQuery<ArtistId>(query, range);
return Utils::execQuery<ArtistId>(query, params.range);
}
RangeResults<ReleaseId> Listen::getTopReleases(Session& session, UserId userId, ScrobblingBackend backend, const std::vector<ClusterId>& clusterIds, std::optional<Range> range)
RangeResults<ReleaseId> Listen::getTopReleases(Session& session, const StatsFindParameters& params)
{
session.checkReadTransaction();
auto query{ createReleasesQuery(session.getDboSession(), userId, backend, clusterIds)
auto query{ createReleasesQuery(session.getDboSession(), params)
.orderBy("COUNT(r.id) DESC")
.groupBy("r.id") };
return Utils::execQuery<ReleaseId>(query, range);
return Utils::execQuery<ReleaseId>(query, params.range);
}
RangeResults<TrackId> Listen::getTopTracks(Session& session, UserId userId, ScrobblingBackend backend, const std::vector<ClusterId>& clusterIds, std::optional<Range> range)
RangeResults<TrackId> Listen::getTopTracks(Session& session, const StatsFindParameters& params)
{
session.checkReadTransaction();
auto query{ createTracksQuery(session.getDboSession(), userId, ArtistId{}, backend, clusterIds)
auto query{ createTracksQuery(session.getDboSession(), params)
.orderBy("COUNT(t.id) DESC")
.groupBy("t.id") };
return Utils::execQuery<TrackId>(query, range);
return Utils::execQuery<TrackId>(query, params.range);
}
RangeResults<TrackId> Listen::getTopTracks(Session& session, UserId userId, ArtistId artistId, ScrobblingBackend backend, const std::vector<ClusterId>& clusterIds, std::optional<Range> range)
RangeResults<ArtistId> Listen::getRecentArtists(Session& session, const ArtistStatsFindParameters& params)
{
session.checkReadTransaction();
auto query{ createTracksQuery(session.getDboSession(), userId, artistId, backend, clusterIds)
.orderBy("COUNT(t.id) DESC")
.groupBy("t.id") };
return Utils::execQuery<TrackId>(query, range);
}
RangeResults<ArtistId> Listen::getRecentArtists(Session& session, UserId userId, ScrobblingBackend backend, const std::vector<ClusterId>& clusterIds, std::optional<TrackArtistLinkType> linkType, std::optional<Range> range)
{
session.checkReadTransaction();
auto query{ createArtistsQuery(session.getDboSession(), userId, backend, clusterIds, linkType)
auto query{ createArtistsQuery(session.getDboSession(), params)
.groupBy("a.id").having("l.date_time = MAX(l.date_time)")
.orderBy("l.date_time DESC") };
return Utils::execQuery<ArtistId>(query, range);
return Utils::execQuery<ArtistId>(query, params.range);
}
RangeResults<ReleaseId> Listen::getRecentReleases(Session& session, UserId userId, ScrobblingBackend backend, const std::vector<ClusterId>& clusterIds, std::optional<Range> range)
RangeResults<ReleaseId> Listen::getRecentReleases(Session& session, const StatsFindParameters& params)
{
session.checkReadTransaction();
auto query{ createReleasesQuery(session.getDboSession(), userId, backend, clusterIds)
auto query{ createReleasesQuery(session.getDboSession(), params)
.groupBy("r.id").having("l.date_time = MAX(l.date_time)")
.orderBy("l.date_time DESC") };
return Utils::execQuery<ReleaseId>(query, range);
return Utils::execQuery<ReleaseId>(query, params.range);
}
RangeResults<TrackId> Listen::getRecentTracks(Session& session, UserId userId, ScrobblingBackend backend, const std::vector<ClusterId>& clusterIds, std::optional<Range> range)
RangeResults<TrackId> Listen::getRecentTracks(Session& session, const StatsFindParameters& params)
{
session.checkReadTransaction();
auto query{ createTracksQuery(session.getDboSession(), userId, ArtistId{}, backend, clusterIds)
auto query{ createTracksQuery(session.getDboSession(), params)
.groupBy("t.id").having("l.date_time = MAX(l.date_time)")
.orderBy("l.date_time DESC") };
return Utils::execQuery<TrackId>(query, range);
return Utils::execQuery<TrackId>(query, params.range);
}
std::size_t Listen::getCount(Session& session, UserId userId, TrackId trackId)
+78
View File
@@ -0,0 +1,78 @@
/*
* Copyright (C) 2013-2016 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "database/MediaLibrary.hpp"
#include "database/ScanSettings.hpp"
#include "database/Session.hpp"
#include "database/Track.hpp"
#include "IdTypeTraits.hpp"
#include "PathTraits.hpp"
#include "StringViewTraits.hpp"
namespace Database
{
MediaLibrary::MediaLibrary(const std::filesystem::path& p, std::string_view name)
: _path{ p },
_name{ std::string {name, 0, maxNameLength} }
{
}
MediaLibrary::pointer MediaLibrary::create(Session& session, const std::filesystem::path& p, std::string_view name)
{
return session.getDboSession().add(std::unique_ptr<MediaLibrary>{ new MediaLibrary{ p, name } });
}
std::size_t MediaLibrary::getCount(Session& session)
{
session.checkReadTransaction();
return session.getDboSession().query<int>("SELECT COUNT(*) FROM cluster");
}
MediaLibrary::pointer MediaLibrary::find(Session& session, MediaLibraryId id)
{
session.checkReadTransaction();
return session.getDboSession().find<MediaLibrary>().where("id = ?").bind(id).resultValue();
}
MediaLibrary::pointer MediaLibrary::find(Session& session, std::string_view name)
{
session.checkReadTransaction();
return session.getDboSession().find<MediaLibrary>().where("name = ?").bind(name).resultValue();
}
MediaLibrary::pointer MediaLibrary::find(Session& session, const std::filesystem::path& p)
{
session.checkReadTransaction();
return session.getDboSession().find<MediaLibrary>().where("path = ?").bind(p).resultValue();
}
void MediaLibrary::find(Session& session, std::function<void(const MediaLibrary::pointer&)> func)
{
session.checkReadTransaction();
auto results{ session.getDboSession().find<MediaLibrary>().resultList() };
for (const auto& result : results)
func(result);
}
} // namespace Database
+62
View File
@@ -309,6 +309,67 @@ CREATE TABLE IF NOT EXISTS "track_backup" (
session.getDboSession().execute("UPDATE scan_settings SET scan_version = scan_version + 1");
}
void migrateFromV50(Session& session)
{
// MediaLibrary support
session.getDboSession().execute(R"(CREATE TABLE IF NOT EXISTS "media_library" (
"id" integer primary key autoincrement,
"version" integer not null,
"path" text not null,
"name" text not null
))");
const int scanSettingsId{ session.getDboSession().query<int>("SELECT id FROM scan_settings") };
// Convert the existing media_directory in the scan_settings table to a media_library with id '1'
session.getDboSession().execute(R"(INSERT INTO "media_library" ("id", "version", "path", "name")
SELECT 1, 0, s_s.media_directory, "Main"
FROM scan_settings s_s
WHERE id = ?)").bind(scanSettingsId);
// Remove the outdated column in scan_settings
session.getDboSession().execute("ALTER TABLE scan_settings DROP media_directory");
// Add the media_library column in tracks, with id '1'
session.getDboSession().execute(R"(
CREATE TABLE IF NOT EXISTS "track_backup" (
"id" integer primary key autoincrement,
"version" integer not null,
"scan_version" integer not null,
"track_number" integer,
"disc_number" integer,
"total_track" integer,
"disc_subtitle" text not null,
"name" text not null,
"duration" integer,
"bitrate" integer not null,
"date" text,
"year" integer,
"original_date" text,
"original_year" integer,
"file_path" text not null,
"file_last_write" text,
"file_added" text,
"has_cover" boolean not null,
"mbid" text not null,
"recording_mbid" text not null,
"copyright" text not null,
"copyright_url" text not null,
"track_replay_gain" real,
"release_replay_gain" real,
"artist_display_name" text not null,
"release_id" bigint,
"media_library_id" bigint,
constraint "fk_track_release" foreign key ("release_id") references "release" ("id") on delete cascade deferrable initially deferred,
constraint "fk_track_media_library" foreign key ("media_library_id") references "media_library" ("id") on delete set null deferrable initially deferred
))");
// Migrate data, with the new media_library_id field set to 1
session.getDboSession().execute("INSERT INTO track_backup SELECT id, version, scan_version, track_number, disc_number, total_track, disc_subtitle, name, duration, bitrate, date, year, original_date, original_year, file_path, file_last_write, file_added, has_cover, mbid, recording_mbid, copyright, copyright_url, track_replay_gain, release_replay_gain, artist_display_name, release_id, 1 FROM track");
session.getDboSession().execute("DROP TABLE track");
session.getDboSession().execute("ALTER TABLE track_backup RENAME TO track");
}
void doDbMigration(Session& session)
{
static const std::string outdatedMsg{ "Outdated database, please rebuild it (delete the .db file and restart)" };
@@ -337,6 +398,7 @@ CREATE TABLE IF NOT EXISTS "track_backup" (
{47, migrateFromV47},
{48, migrateFromV48},
{49, migrateFromV49},
{50, migrateFromV50},
};
{
+1 -1
View File
@@ -26,7 +26,7 @@ namespace Database
class Session;
using Version = std::size_t;
static constexpr Version LMS_DATABASE_VERSION{ 50 };
static constexpr Version LMS_DATABASE_VERSION{ 51 };
class VersionInfo
{
public:
+54
View File
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2021 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#include <filesystem>
#include <Wt/Dbo/SqlTraits.h>
namespace Wt::Dbo
{
template<>
struct sql_value_traits<std::filesystem::path>
{
static std::string type(SqlConnection* conn, int size)
{
return sql_value_traits<std::string>::type(conn, size);
}
static void bind(const std::filesystem::path& path, SqlStatement* statement, int column, int /* size */)
{
statement->bind(column, path.string());
}
static bool read(std::filesystem::path& p, SqlStatement* statement, int column, int size)
{
std::string s;
bool result = statement->getResult(column, &s, size);
if (!result)
return false;
p = std::filesystem::path{ s };
return true;
}
};
}
+12 -18
View File
@@ -42,18 +42,23 @@ namespace Database
{
auto query{ session.getDboSession().query<ResultType>("SELECT " + std::string{ itemToSelect } + " from release r") };
if (params.sortMethod == ReleaseSortMethod::LastWritten
if (params.sortMethod == ReleaseSortMethod::ArtistNameThenName
|| params.sortMethod == ReleaseSortMethod::LastWritten
|| params.sortMethod == ReleaseSortMethod::Date
|| params.sortMethod == ReleaseSortMethod::OriginalDate
|| params.sortMethod == ReleaseSortMethod::OriginalDateDesc
|| params.writtenAfter.isValid()
|| params.dateRange
|| params.artist.isValid()
|| params.clusters.size() == 1)
|| params.clusters.size() == 1
|| params.mediaLibrary.isValid())
{
query.join("track t ON t.release_id = r.id");
}
if (params.mediaLibrary.isValid())
query.where("t.media_library_id = ?").bind(params.mediaLibrary);
if (!params.releaseType.empty())
{
query.join("release_release_type r_r_t ON r_r_t.release_id = r.id");
@@ -82,7 +87,8 @@ namespace Database
.where("s_r.sync_state <> ?").bind(SyncState::PendingRemove);
}
if (params.artist.isValid())
if (params.artist.isValid()
|| params.sortMethod == ReleaseSortMethod::ArtistNameThenName)
{
query.join("artist a ON a.id = t_a_l.artist_id")
.join("track_artist_link t_a_l ON t_a_l.track_id = t.id")
@@ -163,6 +169,9 @@ namespace Database
case ReleaseSortMethod::Name:
query.orderBy("r.name COLLATE NOCASE");
break;
case ReleaseSortMethod::ArtistNameThenName:
query.orderBy("a.name COLLATE NOCASE, r.name COLLATE NOCASE");
break;
case ReleaseSortMethod::Random:
query.orderBy("RANDOM()");
break;
@@ -276,21 +285,6 @@ namespace Database
return session.getDboSession().query<int>("SELECT COUNT(*) FROM release");
}
RangeResults<ReleaseId> Release::findIdsOrderedByArtist(Session& session, std::optional<Range> range)
{
session.checkReadTransaction();
// TODO merge with find
auto query{ session.getDboSession().query<ReleaseId>(
"SELECT DISTINCT r.id FROM release r"
" INNER JOIN track t ON r.id = t.release_id"
" INNER JOIN track_artist_link t_a_l ON t_a_l.track_id = t.id"
" INNER JOIN artist a ON t_a_l.artist_id = a.id")
.orderBy("a.name COLLATE NOCASE, r.name COLLATE NOCASE") };
return Utils::execQuery<ReleaseId>(query, range);
}
RangeResults<ReleaseId> Release::findOrphanIds(Session& session, std::optional<Range> range)
{
session.checkReadTransaction();
+2 -10
View File
@@ -21,12 +21,9 @@
#include <Wt/Dbo/WtSqlTraits.h>
#include "utils/Path.hpp"
#include "utils/ILogger.hpp"
#include "utils/String.hpp"
#include "database/Cluster.hpp"
#include "database/MediaLibrary.hpp"
#include "database/Session.hpp"
#include "utils/String.hpp"
namespace Database
{
@@ -68,11 +65,6 @@ namespace Database
return StringUtils::splitString(_extraTagsToScan, ";");
}
void ScanSettings::setMediaDirectory(const std::filesystem::path& p)
{
_mediaDirectory = StringUtils::stringTrimEnd(p.string(), "/\\");
}
void ScanSettings::setExtraTagsToScan(const std::vector<std::string_view>& extraTags)
{
std::string newTagsToScan{ StringUtils::joinStrings(extraTags, ";") };
+6
View File
@@ -29,6 +29,7 @@
#include "database/Cluster.hpp"
#include "database/Db.hpp"
#include "database/Listen.hpp"
#include "database/MediaLibrary.hpp"
#include "database/Release.hpp"
#include "database/ScanSettings.hpp"
#include "database/StarredArtist.hpp"
@@ -42,6 +43,7 @@
#include "database/TransactionChecker.hpp"
#include "database/User.hpp"
#include "EnumSetTraits.hpp"
#include "PathTraits.hpp"
#include "Migration.hpp"
namespace Database
@@ -81,6 +83,7 @@ namespace Database
_session.mapClass<Cluster>("cluster");
_session.mapClass<ClusterType>("cluster_type");
_session.mapClass<Listen>("listen");
_session.mapClass<MediaLibrary>("media_library");
_session.mapClass<Release>("release");
_session.mapClass<ReleaseType>("release_type");
_session.mapClass<ScanSettings>("scan_settings");
@@ -152,7 +155,10 @@ namespace Database
_session.execute("CREATE INDEX IF NOT EXISTS track_release_idx ON track(release_id)");
_session.execute("CREATE INDEX IF NOT EXISTS track_file_last_write_idx ON track(file_last_write)");
_session.execute("CREATE INDEX IF NOT EXISTS track_date_idx ON track(date)");
_session.execute("CREATE INDEX IF NOT EXISTS track_year_idx ON track(year)");
_session.execute("CREATE INDEX IF NOT EXISTS track_original_date_idx ON track(original_date)");
_session.execute("CREATE INDEX IF NOT EXISTS track_original_year_idx ON track(original_year)");
_session.execute("CREATE INDEX IF NOT EXISTS track_media_library_idx ON track(media_library_id)");
_session.execute("CREATE INDEX IF NOT EXISTS tracklist_name_idx ON tracklist(name)");
_session.execute("CREATE INDEX IF NOT EXISTS tracklist_user_idx ON tracklist(user_id)");
_session.execute("CREATE INDEX IF NOT EXISTS track_features_track_idx ON track_features(track_id)");
+11 -8
View File
@@ -19,15 +19,18 @@
#pragma once
#include <string_view>
#include <Wt/Dbo/SqlTraits.h>
namespace Wt::Dbo
{
template<>
struct sql_value_traits<std::string_view>
{
static void bind(std::string_view str, SqlStatement *statement, int column, int /* size */)
{
statement->bind(column, std::string {str});
}
};
template<>
struct sql_value_traits<std::string_view>
{
static void bind(std::string_view str, SqlStatement* statement, int column, int /* size */)
{
statement->bind(column, std::string{ str });
}
};
}
+4
View File
@@ -23,6 +23,7 @@
#include "database/Artist.hpp"
#include "database/Cluster.hpp"
#include "database/MediaLibrary.hpp"
#include "database/Release.hpp"
#include "database/TrackArtistLink.hpp"
#include "database/TrackFeatures.hpp"
@@ -140,6 +141,9 @@ namespace Database
if (params.trackNumber)
query.where("t.track_number = ?").bind(*params.trackNumber);
if (params.mediaLibrary.isValid())
query.where("t.media_library_id = ?").bind(params.mediaLibrary);
switch (params.sortMethod)
{
case TrackSortMethod::None: