Skip to content

Commit

Permalink
Merge pull request #750 from podverse/develop
Browse files Browse the repository at this point in the history
Release v4.16.16
  • Loading branch information
mitchdowney authored Apr 27, 2024
2 parents 9dbf50a + 74060b9 commit bee5df8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
30 changes: 18 additions & 12 deletions src/lib/utility/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/services/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}

Expand Down

0 comments on commit bee5df8

Please sign in to comment.