optiomisations on history queries

This commit is contained in:
CyferShepard
2024-12-27 14:53:14 +02:00
parent 95d3a0f0fc
commit 58804e08d3
2 changed files with 14 additions and 14 deletions

View File

@@ -59,7 +59,9 @@ async function query({
const joinConditions = join.conditions
.map((condition, index) => {
const conjunction = index === 0 ? "" : condition.type ? condition.type.toUpperCase() : "AND";
return `${conjunction} ${wrapField(condition.first)} ${condition.operator} ${wrapField(condition.second)}`;
return `${conjunction} ${wrapField(condition.first)} ${condition.operator} ${
condition.second ? wrapField(condition.second) : `'${condition.value}'`
}`;
})
.join(" ");
const joinQuery = ` ${join.type.toUpperCase()} JOIN ${join.table} AS ${join.alias} ON ${joinConditions}`;

View File

@@ -1101,8 +1101,8 @@ router.get("/getHistory", async (req, res) => {
table: "jf_library_episodes",
alias: "e",
conditions: [
{ first: "a.EpisodeId", operator: "=", second: "e.EpisodeId", type: "and" },
{ first: "a.SeasonId", operator: "=", second: "e.SeasonId", type: "and" },
{ first: "a.EpisodeId", operator: "=", second: "e.EpisodeId" },
{ first: "a.SeasonId", operator: "=", second: "e.SeasonId" },
],
},
{
@@ -1110,7 +1110,7 @@ router.get("/getHistory", async (req, res) => {
table: "jf_library_items",
alias: "i",
conditions: [
{ first: "i.Id", operator: "=", second: "a.NowPlayingItemId", type: "or" },
{ first: "i.Id", operator: "=", second: "a.NowPlayingItemId" },
{ first: "e.SeriesId", operator: "=", second: "i.Id", type: "or" },
],
},
@@ -1148,7 +1148,10 @@ router.post("/getLibraryHistory", async (req, res) => {
type: "inner",
table: "jf_library_items",
alias: "i",
conditions: [{ first: "i.Id", operator: "=", second: "a.NowPlayingItemId" }],
conditions: [
{ first: "i.Id", operator: "=", second: "a.NowPlayingItemId" },
{ first: "i.ParentId", operator: "=", value: libraryid },
],
},
{
type: "left",
@@ -1160,7 +1163,7 @@ router.post("/getLibraryHistory", async (req, res) => {
],
},
],
where: [{ column: "i.ParentId", operator: "=", value: libraryid }],
order_by: "ActivityDateInserted",
sort_order: "desc",
pageNumber: page,
@@ -1206,13 +1209,13 @@ router.post("/getItemHistory", async (req, res) => {
table: "jf_library_items",
alias: "i",
conditions: [
{ first: "i.Id", operator: "=", second: "a.NowPlayingItemId", type: "or" },
{ first: "i.Id", operator: "=", second: "a.NowPlayingItemId" },
{ first: "e.SeriesId", operator: "=", second: "i.Id", type: "or" },
],
},
],
where: [
{ column: "a.EpisodeId", operator: "=", value: itemid, type: "or" },
{ column: "a.EpisodeId", operator: "=", value: itemid },
{ column: "a.SeasonId", operator: "=", value: itemid, type: "or" },
{ column: "a.NowPlayingItemId", operator: "=", value: itemid, type: "or" },
],
@@ -1222,11 +1225,6 @@ router.post("/getItemHistory", async (req, res) => {
pageSize: size,
});
// const groupedResults = rows.map((item) => ({
// ...item,
// results: [],
// }));
res.send({ current_page: page, pages: result.pages, results: result.results });
} catch (error) {
console.log(error);
@@ -1265,7 +1263,7 @@ router.post("/getUserHistory", async (req, res) => {
table: "jf_library_items",
alias: "i",
conditions: [
{ first: "i.Id", operator: "=", second: "a.NowPlayingItemId", type: "or" },
{ first: "i.Id", operator: "=", second: "a.NowPlayingItemId" },
{ first: "e.SeriesId", operator: "=", second: "i.Id", type: "or" },
],
},