From 8be2e8976003486830777c20dde6a9b48a6f6d0f Mon Sep 17 00:00:00 2001 From: Mitch Downey Date: Sat, 27 Apr 2024 10:15:28 -0500 Subject: [PATCH 1/3] Fix popularity orderBy so null appears at the bottom --- src/lib/utility/index.ts | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/lib/utility/index.ts b/src/lib/utility/index.ts index 5c958161..9d201d7d 100644 --- a/src/lib/utility/index.ts +++ b/src/lib/utility/index.ts @@ -151,45 +151,50 @@ export const addOrderByToQuery = (qb, type, sort, sortDateKey, allowRandom, isFr } else if (sort === 'live-item-start-desc') { qb.orderBy(`liveItem.start`, descKey) } else if (sort === 'top-past-day') { - qb.innerJoin( + qb.leftJoin( ormStatsType, `stats_${type}`, `${type}.id = stats_${type}.${statsParentId}_id AND stats_${type}.timeframe = :timeframe`, { timeframe: 'daily' } ) - qb.orderBy(`stats_${type}.play_count`, descKey) + qb.addOrderBy(`CASE WHEN stats_${type}.play_count IS NULL THEN 1 ELSE 0 END`, 'ASC') + qb.addOrderBy(`stats_${type}.play_count`, descKey) } else if (sort === 'top-past-week') { - qb.innerJoin( + qb.leftJoin( ormStatsType, `stats_${type}`, `${type}.id = stats_${type}.${statsParentId}_id AND stats_${type}.timeframe = :timeframe`, { timeframe: 'weekly' } ) - qb.orderBy(`stats_${type}.play_count`, descKey) + qb.addOrderBy(`CASE WHEN stats_${type}.play_count IS NULL THEN 1 ELSE 0 END`, 'ASC') + qb.addOrderBy(`stats_${type}.play_count`, descKey) } else if (sort === 'top-past-month') { - qb.innerJoin( + qb.leftJoin( ormStatsType, `stats_${type}`, `${type}.id = stats_${type}.${statsParentId}_id AND stats_${type}.timeframe = :timeframe`, { timeframe: 'monthly' } ) - qb.orderBy(`stats_${type}.play_count`, descKey) + qb.addOrderBy(`CASE WHEN stats_${type}.play_count IS NULL THEN 1 ELSE 0 END`, 'ASC') + qb.addOrderBy(`stats_${type}.play_count`, descKey) } else if (sort === 'top-past-year') { - qb.innerJoin( + qb.leftJoin( ormStatsType, `stats_${type}`, `${type}.id = stats_${type}.${statsParentId}_id AND stats_${type}.timeframe = :timeframe`, { timeframe: 'yearly' } ) - qb.orderBy(`stats_${type}.play_count`, descKey) + qb.addOrderBy(`CASE WHEN stats_${type}.play_count IS NULL THEN 1 ELSE 0 END`, 'ASC') + qb.addOrderBy(`stats_${type}.play_count`, descKey) } else if (sort === 'top-all-time') { - qb.innerJoin( + qb.leftJoin( ormStatsType, `stats_${type}`, `${type}.id = stats_${type}.${statsParentId}_id AND stats_${type}.timeframe = :timeframe`, { timeframe: 'all_time' } ) - qb.orderBy(`stats_${type}.play_count`, descKey) + qb.addOrderBy(`CASE WHEN stats_${type}.play_count IS NULL THEN 1 ELSE 0 END`, 'ASC') + qb.addOrderBy(`stats_${type}.play_count`, descKey) } else if (sort === 'most-recent') { qb.orderBy(`${type}.${sortDateKey}`, descKey) } else if (sort === 'oldest') { @@ -205,13 +210,14 @@ export const addOrderByToQuery = (qb, type, sort, sortDateKey, allowRandom, isFr } else if (sort === 'episode-number-asc') { qb.orderBy(`${type}.itunesEpisode`, ascKey) } else { - qb.innerJoin( + qb.leftJoin( ormStatsType, `stats_${type}`, `${type}.id = stats_${type}.${type}_id AND stats_${type}.timeframe = :timeframe`, { timeframe: 'weekly' } ) - qb.orderBy(`stats_${type}.play_count`, descKey) + qb.addOrderBy(`CASE WHEN stats_${type}.play_count IS NULL THEN 1 ELSE 0 END`, 'ASC') + qb.addOrderBy(`stats_${type}.play_count`, descKey) } return qb From b7fce94da3f56d953138048ba6e91d8133b39aca Mon Sep 17 00:00:00 2001 From: Mitch Downey Date: Sat, 27 Apr 2024 10:15:57 -0500 Subject: [PATCH 2/3] Prevent "custom-url" from throwing errors in stats jobs --- src/services/stats.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/services/stats.ts b/src/services/stats.ts index 02130410..9c869ae1 100644 --- a/src/services/stats.ts +++ b/src/services/stats.ts @@ -351,6 +351,10 @@ const savePageviewsToDatabase = async (finalPagePath: string, timeRange, data, j const idStartIndex = label.indexOf(`${finalPagePath}/`) + (finalPagePath.length + 1) const id = label.substr(idStartIndex) + if (id === 'custom-url') { + continue + } + // max length of ids = 14 if (id.length > 14) { console.log('id too long!', id) @@ -359,13 +363,11 @@ const savePageviewsToDatabase = async (finalPagePath: string, timeRange, data, j const sum_daily_nb_uniq_visitors = row.sum_daily_nb_uniq_visitors - if (id) { - const rawSQLUpdate = generateSetNewCountQuery(finalPagePath, timeRange, id, sum_daily_nb_uniq_visitors) - await getConnection().createEntityManager().query(rawSQLUpdate) - } + const rawSQLUpdate = generateSetNewCountQuery(finalPagePath, timeRange, id, sum_daily_nb_uniq_visitors) + await getConnection().createEntityManager().query(rawSQLUpdate) } catch (err) { console.log('row err', err) - console.log('row', row) + console.log('row', row.label) } } From 74060b9bf90ab84c3848b02204b05998407f2b83 Mon Sep 17 00:00:00 2001 From: Mitch Downey Date: Sat, 27 Apr 2024 10:16:19 -0500 Subject: [PATCH 3/3] Bump to version 4.16.16 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 51694f8d..eb55eee8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "podverse-api", - "version": "4.16.15", + "version": "4.16.16", "description": "Data API, database migration scripts, and backend services for all Podverse models.", "contributors": [ "Mitch Downey"