Skip to content

Commit 5857306

Browse files
authored
fix(sanity): broaden missing transcripts query to all content types and report total count (#705)
1 parent 91e95b7 commit 5857306

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

‎.github/workflows/sync-missing-youtube-transcripts.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ on:
1111
options:
1212
- production
1313
- dev
14+
batch_size:
15+
description: "Batch size (number of videos to process in this run)"
16+
required: true
17+
default: "50"
18+
type: string
1419

1520
jobs:
1621
sync-transcripts:
@@ -39,3 +44,4 @@ jobs:
3944
SANITY_STUDIO_PROJECT_ID: ${{ vars.SANITY_STUDIO_PROJECT_ID }}
4045
SANITY_STUDIO_DATASET: ${{ inputs.dataset }}
4146
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
47+
SYNC_BATCH_SIZE: ${{ inputs.batch_size }}

‎apps/sanity/functions/sync-missing-youtube-transcripts/index.ts‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,27 @@ export const handler = scheduledEventHandler(async ({ context }) => {
259259
useCdn: false,
260260
});
261261

262+
const batchSize = parseInt(process.env.SYNC_BATCH_SIZE || "50", 10);
263+
262264
console.log(
263265
`[Sync Missing YouTube Transcripts] Querying documents with YouTube URLs missing transcripts in project ${projectId}, dataset ${dataset}...`,
264266
);
265267

268+
const totalMissing = await client.fetch<number>(
269+
`count(*[_type in ["post", "podcast", "course", "lesson", "short"] && (defined(youtube) || defined(listenLinks.youtube)) && !defined(transcript) && !(_id in path("drafts.**"))])`,
270+
);
271+
272+
console.log(
273+
`[Sync Missing YouTube Transcripts] Total documents currently missing transcripts in ${dataset}: ${totalMissing}`,
274+
);
275+
276+
if (totalMissing === 0) {
277+
console.log(
278+
"[Sync Missing YouTube Transcripts] All videos currently have linked transcripts. Done.",
279+
);
280+
return;
281+
}
282+
266283
const missingDocs = await client.fetch<
267284
Array<{
268285
_id: string;
@@ -271,25 +288,19 @@ export const handler = scheduledEventHandler(async ({ context }) => {
271288
youtube: string;
272289
}>
273290
>(
274-
`*[_type in ["post", "podcast"] && defined(youtube) && !defined(transcript) && !(_id in path("drafts.**"))][0...25]{
291+
`*[_type in ["post", "podcast", "course", "lesson", "short"] && (defined(youtube) || defined(listenLinks.youtube)) && !defined(transcript) && !(_id in path("drafts.**"))][0...$batchSize]{
275292
_id,
276293
_type,
277294
title,
278-
youtube
295+
"youtube": coalesce(youtube, listenLinks.youtube)
279296
}`,
297+
{ batchSize },
280298
);
281299

282300
console.log(
283-
`[Sync Missing YouTube Transcripts] Found ${missingDocs.length} documents missing transcripts.`,
301+
`[Sync Missing YouTube Transcripts] Processing batch of ${missingDocs.length} documents (batch limit: ${batchSize})...`,
284302
);
285303

286-
if (missingDocs.length === 0) {
287-
console.log(
288-
"[Sync Missing YouTube Transcripts] All videos currently have linked transcripts. Done.",
289-
);
290-
return;
291-
}
292-
293304
let successCount = 0;
294305
let failCount = 0;
295306

0 commit comments

Comments
 (0)