Skip to content

Commit

Permalink
Merge pull request #732 from podverse/develop
Browse files Browse the repository at this point in the history
Release v4.16.5
  • Loading branch information
mitchdowney committed Apr 10, 2024
2 parents 5b38a4e + 7ca14a5 commit d676b03
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "podverse-api",
"version": "4.16.4",
"version": "4.16.5",
"description": "Data API, database migration scripts, and backend services for all Podverse models.",
"contributors": [
"Mitch Downey"
Expand Down Expand Up @@ -41,6 +41,7 @@
"dev:scripts:receiveErrorMessageFromQueue": "ts-node -r dotenv/config -r tsconfig-paths/register ./src/scripts/queue/receiveErrorMessageFromQueue.ts",
"dev:scripts:refreshEpisodesMostRecentMaterializedView": "ts-node -r dotenv/config -r tsconfig-paths/register ./src/scripts/episodes/refreshEpisodesMostRecentMaterializedView.ts",
"dev:scripts:refreshMediaRefsVideosMaterializedView": "ts-node -r dotenv/config -r tsconfig-paths/register ./src/scripts/mediaRefs_videos/refreshMediaRefsVideosMaterializedView.ts",
"dev:scripts:removeDeadChapters": "ts-node -r dotenv/config -r tsconfig-paths/register ./src/scripts/mediaRefs/removeDeadChapters.ts",
"dev:scripts:removeDeadEpisodes": "ts-node -r dotenv/config -r tsconfig-paths/register ./src/scripts/episodes/removeDeadEpisodes.ts",
"dev:scripts:syncWithFeedUrlsCSVDump": "ts-node -r dotenv/config -r tsconfig-paths/register ./src/scripts/podcastIndex/syncWithFeedUrlsCSVDump.ts",
"dev:scripts:updateRecentEpisodesTables": "ts-node -r dotenv/config -r tsconfig-paths/register ./src/scripts/recentEpisodes/updateRecentEpisodesTables.ts",
Expand Down
11 changes: 7 additions & 4 deletions src/controllers/episode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,9 @@ const retrieveLatestChapters = async (id, includeNonToc = true) => {

const chapterHash = uuidv5(JSON.stringify(chapterInfoToHash), uuidNIL)

const imageUrl = newChapter?.img?.replace(/ /g, '%20') || null
const linkUrl = newChapter?.url?.replace(/ /g, '%20') || null

// If a chapter with that chapterHash already exists, then update it.
// If it does not exist, then create a new mediaRef with isOfficialChapter = true.
const existingChapter = existingChapters.find((x) => x.chapterHash === chapterHash)
Expand All @@ -784,10 +787,10 @@ const retrieveLatestChapters = async (id, includeNonToc = true) => {
{
endTime: roundedEndTime,
id: existingChapter.id,
imageUrl: newChapter.img || null,
imageUrl,
isOfficialChapter: true,
isPublic: true,
linkUrl: newChapter.url || null,
linkUrl,
startTime: roundedStartTime,
title: newChapter.title,
episodeId: id,
Expand All @@ -799,10 +802,10 @@ const retrieveLatestChapters = async (id, includeNonToc = true) => {
} else {
await createMediaRef({
endTime: roundedEndTime,
imageUrl: newChapter.img || null,
imageUrl,
isOfficialChapter: true,
isPublic: true,
linkUrl: newChapter.url || null,
linkUrl,
startTime: roundedStartTime,
title: newChapter.title,
owner: superUserId,
Expand Down
22 changes: 22 additions & 0 deletions src/controllers/mediaRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,27 @@ const refreshMediaRefsVideosMaterializedView = async () => {
await em.query('REFRESH MATERIALIZED VIEW CONCURRENTLY "mediaRefs_videos"')
}

const removeDeadChapters = async () => {
const em = await getConnection().createEntityManager()
try {
for (let i = 0; i < 10000; i++) {
console.log('removeDeadChapters i:', i)
await em.query(`
DELETE FROM "mediaRefs"
WHERE "id" IN (
SELECT "id"
FROM "mediaRefs"
WHERE "isOfficialChapter" = TRUE
AND "isPublic" = FALSE
LIMIT 100
);
`)
}
} catch (error) {
console.log('deleteHiddenMediaRefs error:', error)
}
}

export {
createMediaRef,
deleteMediaRef,
Expand All @@ -374,6 +395,7 @@ export {
getPublicMediaRefsByEpisodeMediaUrl,
getPublicMediaRefsByEpisodeGuid,
refreshMediaRefsVideosMaterializedView,
removeDeadChapters,
updateMediaRef,
updateSoundBites
}
26 changes: 26 additions & 0 deletions src/scripts/mediaRefs/removeDeadChapters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { removeDeadChapters } from '~/controllers/mediaRef'
import { connectToDb } from '~/lib/db'
;(async function () {
try {
const customLimit = (process.argv.length > 2 ? process.argv[2] : 100000) as any
const customLimitInt = parseInt(customLimit, 10)

const customOffset = (process.argv.length > 3 ? process.argv[3] : 0) as any
const customOffsetInt = parseInt(customOffset, 10)

if (!customLimitInt) {
console.log('customLimit parameter must be an integer.')
return
}

if (!customOffsetInt && customOffsetInt !== 0) {
console.log('customOffset parameter must be an integer.')
return
}
await connectToDb()
await removeDeadChapters()
} catch (error) {
console.log(error)
}
return
})()
6 changes: 5 additions & 1 deletion src/services/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
podcastItunesTypeDefaultValue
} from 'podverse-shared'
import { getRepository, In, Not } from 'typeorm'
import isUUID from 'validator/lib/isUUID'
import { config } from '~/config'
import { updateSoundBites } from '~/controllers/mediaRef'
import { getPodcast } from '~/controllers/podcast'
Expand Down Expand Up @@ -371,7 +372,10 @@ export const parseFeedUrl = async (feedUrl, forceReparsing = false, cacheBust =
// guid is deprecated
podcast.guid = meta.guid
// podcastGuid is the column we want to use going forward
podcast.podcastGuid = meta.guid

if (meta.guid && isUUID(meta.guid)) {
podcast.podcastGuid = meta.guid
}

const hasNewImageUrl = meta.imageURL && podcast.imageUrl !== meta.imageURL
podcast.imageUrl = meta.imageURL
Expand Down

0 comments on commit d676b03

Please sign in to comment.