Skip to content

Conversation

@tanflem
Copy link
Contributor

@tanflem tanflem commented Dec 5, 2025

Summary by CodeRabbit

  • New Features

    • Add queries to inspect video and variant records in the search index with detailed mismatch and missing-variant reports.
    • Add mutations to trigger reindexing of videos and video variants in the search index.
  • Removed

    • Removed the Cloudflare R2 multipart upload flow and its related API surface.
  • Tests

    • Added comprehensive unit tests covering index checks, update mutations, and authorization/error scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

@linear
Copy link

linear bot commented Dec 5, 2025

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 5, 2025

Walkthrough

Removes Cloudflare R2 multipart upload GraphQL types and mutations; adds Algolia index check/update GraphQL types, queries, and mutations; implements resolvers, Algolia client/config changes, update helpers adjustments, and extensive unit tests for Algolia operations.

Changes

Cohort / File(s) Summary
API schemas
apis/api-gateway/schema.graphql, apis/api-media/schema.graphql
Removed Cloudflare R2 multipart-related types/inputs/mutations. Added Algolia-related types CheckVideoInAlgoliaMismatch, CheckVideoInAlgoliaResult, CheckVideoVariantsInAlgoliaResult; added queries checkVideoInAlgolia, checkVideoVariantsInAlgolia; added mutations updateVideoAlgoliaIndex, updateVideoVariantAlgoliaIndex.
Video Algolia resolvers & tests
apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts, apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.spec.ts
New resolvers implementing checks and updates against Algolia for videos and variants; comprehensive tests covering matches, mismatches, missing variants, access control, error conditions, and mutation flows.
Schema barrels
apis/api-media/src/schema/video/index.ts, apis/api-media/src/schema/video/videoAlgolia/index.ts
Added imports/exports to include the new videoAlgolia module in the video schema.
Algolia client & config
apis/api-media/src/lib/algolia/algoliaClient.ts
Replaced async nullable factory with synchronous getAlgoliaClient(); added eager algoliaConfig that reads required env vars; removed logger parameter and null-return branch.
Algolia update helpers
apis/api-media/src/lib/algolia/algoliaVideoUpdate/algoliaVideoUpdate.ts, apis/api-media/src/lib/algolia/algoliaVideoVariantUpdate/algoliaVideoVariantUpdate.ts
Switched to synchronous getAlgoliaClient() and algoliaConfig usage; removed null-client checks; updated index name usages to algoliaConfig.
Algolia test adjustments
apis/api-media/src/lib/algolia/.../algoliaVideoUpdate.spec.ts, .../algoliaVideoVariantUpdate.spec.ts
Updated mocks to reflect synchronous client and algoliaConfig; introduced shared spies; removed null-client test paths and environment setup.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant GraphQL as GraphQL Resolver
    participant Prisma as Database
    participant Algolia

    Client->>GraphQL: checkVideoInAlgolia(videoId)
    GraphQL->>Prisma: fetch video minimal fields
    Prisma-->>GraphQL: video data (or null)
    GraphQL->>Algolia: getObject(recordId)
    Algolia-->>GraphQL: algolia record (or error)
    GraphQL->>GraphQL: compare fields, collect mismatches
    GraphQL-->>Client: CheckVideoInAlgoliaResult{ok, mismatches, recordUrl}
Loading
sequenceDiagram
    participant Client
    participant GraphQL as GraphQL Resolver
    participant Prisma as Database
    participant Algolia

    Client->>GraphQL: updateVideoAlgoliaIndex(videoId)
    GraphQL->>Prisma: verify video exists
    Prisma-->>GraphQL: video found
    GraphQL->>Algolia: updateVideoInAlgolia(videoId)
    Algolia-->>GraphQL: update result
    GraphQL-->>Client: Boolean (true)
Loading
sequenceDiagram
    participant Client
    participant GraphQL as GraphQL Resolver
    participant Prisma as Database
    participant Algolia

    Client->>GraphQL: checkVideoVariantsInAlgolia(videoId)
    GraphQL->>Prisma: fetch video variants
    Prisma-->>GraphQL: variants list
    loop per variant
        GraphQL->>Algolia: getObject(variantRecordId)
        Algolia-->>GraphQL: record (or null)
        GraphQL->>GraphQL: mark missing/mismatch
    end
    GraphQL-->>Client: CheckVideoVariantsInAlgoliaResult{ok, missingVariants, browseUrl}
Loading
sequenceDiagram
    participant Client
    participant GraphQL as GraphQL Resolver
    participant Prisma as Database
    participant Algolia

    Client->>GraphQL: updateVideoVariantAlgoliaIndex(videoId)
    GraphQL->>Prisma: fetch variants
    Prisma-->>GraphQL: variants list
    loop per variant
        GraphQL->>Algolia: updateVideoVariantInAlgolia(variantId)
        Algolia-->>GraphQL: update result
    end
    GraphQL-->>Client: Boolean (true)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • mikeallisonJS
  • jaco-brink
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding Algolia video troubleshooter backend functionality including validation queries, index mutations, and supporting types.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tannerfleming/vmt-189-backend-video-managment-algolia-troubleshooting

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Dec 5, 2025

View your CI Pipeline Execution ↗ for commit 50cf802

Command Status Duration Result
nx run watch-e2e:e2e ✅ Succeeded 25s View ↗
nx run journeys-admin-e2e:e2e ✅ Succeeded 1m 9s View ↗
nx run short-links-e2e:e2e ✅ Succeeded 5s View ↗
nx run journeys-e2e:e2e ✅ Succeeded 21s View ↗
nx run player-e2e:e2e ✅ Succeeded 3s View ↗
nx run resources-e2e:e2e ✅ Succeeded 9s View ↗
nx run videos-admin-e2e:e2e ✅ Succeeded 4s View ↗
nx run-many --target=vercel-alias --projects=jo... ✅ Succeeded 2s View ↗
Additional runs (20) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2026-01-14 19:02:16 UTC

@github-actions github-actions bot had a problem deploying to Preview - short-links December 5, 2025 16:47 Failure
@github-actions github-actions bot temporarily deployed to Preview - videos-admin December 5, 2025 16:47 Inactive
@github-actions github-actions bot temporarily deployed to Preview - resources December 5, 2025 16:47 Inactive
@github-actions github-actions bot temporarily deployed to Preview - journeys-admin December 5, 2025 16:47 Inactive
@tanflem tanflem self-assigned this Dec 5, 2025
@tanflem tanflem requested a review from mikeallisonJS December 5, 2025 16:48
@tanflem tanflem marked this pull request as draft December 5, 2025 16:48
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

The latest updates on your projects.

Name Status Preview Updated (UTC)
videos-admin ✅ Ready videos-admin preview Thu Jan 15 07:53:31 NZDT 2026

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

The latest updates on your projects.

Name Status Preview Updated (UTC)
watch ✅ Ready watch preview Thu Jan 15 07:53:49 NZDT 2026

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

The latest updates on your projects.

Name Status Preview Updated (UTC)
resources ✅ Ready resources preview Thu Jan 15 07:54:07 NZDT 2026

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

The latest updates on your projects.

Name Status Preview Updated (UTC)
journeys-admin ✅ Ready journeys-admin preview Thu Jan 15 07:54:55 NZDT 2026

@tanflem tanflem marked this pull request as ready for review December 8, 2025 17:24
@github-actions github-actions bot temporarily deployed to Preview - journeys-admin December 8, 2025 17:26 Inactive
@github-actions github-actions bot temporarily deployed to Preview - journeys December 8, 2025 17:26 Inactive
@github-actions github-actions bot temporarily deployed to Preview - resources December 8, 2025 17:26 Inactive
@github-actions github-actions bot requested a deployment to Preview - journeys January 8, 2026 18:25 Pending
@github-actions github-actions bot temporarily deployed to Preview - short-links January 8, 2026 18:25 Inactive
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In @apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts:
- Line 107: Replace the hardcoded languageId '529' used in the variant query
with the video's actual primary language by using video.primaryLanguageId (e.g.,
change where: { languageId: '529' } to where: { languageId:
video.primaryLanguageId }); ensure you handle any type mismatches (string vs
number) and that video.primaryLanguageId is defined before using it so the
variant fetch in videoAlgolia correctly returns the video's primary variant.
- Around line 107-122: The access of video.variants[0] (primaryVariant) can be
undefined; update the logic around primaryVariant in the resolver that computes
isVideoContent and isDownloadable to guard against that: retrieve primaryVariant
via video.variants[0] and then either (A) throw a GraphQLError if a primary
variant is required, or (B) treat a missing variant as
non-video/non-downloadable by setting isVideoContent =
Boolean(primaryVariant?.hls) and isDownloadable = primaryVariant ? (video.label
=== 'collection' || video.label === 'series' ? false :
(primaryVariant.downloadable ?? false)) : false; ensure all uses of
primaryVariant use optional chaining or null checks to avoid undefined access.
🧹 Nitpick comments (3)
apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts (3)

186-195: Simplify redundant logging.

The code logs to both logger and console.error when logger is null. Consider simplifying this pattern since the logger typically handles both cases internally.

♻️ Proposed refactor
-        logger?.error(
+        const logMsg = 'Algolia getObject failed while checking video in Algolia'
+        const logContext = { err, ...context }
+        
+        if (logger != null) {
+          logger.error(logContext, logMsg)
+        } else {
+          console.error(
-          { err, ...context },
-          'Algolia getObject failed while checking video in Algolia'
-        )
-
-        if (logger == null) {
-          console.error(
-            `Algolia getObject failed while checking video in Algolia (videoId=${videoId}, appId=${appId}, videosIndex=${videosIndex}): ${errorString}`
+            `${logMsg} (videoId=${videoId}, appId=${appId}, videosIndex=${videosIndex}): ${errorString}`,
+            logContext
           )
         }

223-239: Consider logging errors in the catch block.

The catch block at line 236 silently adds variants to missingVariants without logging the underlying error. This makes it difficult to distinguish between truly missing variants and those that failed due to other errors (network issues, permission problems, etc.).

📝 Suggested enhancement
         } catch {
+          logger?.warn(
+            { variantId: variant.id, videoId },
+            'Failed to fetch variant from Algolia'
+          )
           missingVariants.push(variant.id)
         }

Or capture the error to include in the response:

-        } catch {
+        } catch (err) {
+          logger?.warn(
+            { err, variantId: variant.id, videoId },
+            'Failed to fetch variant from Algolia'
+          )
           missingVariants.push(variant.id)
         }

229-231: Use consistent null checking.

Line 231 uses loose equality (== null) for the first check but strict equality (=== videoId) for the second. While == null correctly checks for both null and undefined, using strict equality throughout is more consistent with modern JavaScript/TypeScript conventions.

♻️ Proposed refactor
           const objectIdMatches = record.objectID === variant.id
           const videoIdMatches =
-            record.videoId == null || record.videoId === videoId
+            (record.videoId === null || record.videoId === undefined) || record.videoId === videoId

Or use optional chaining if appropriate:

           const videoIdMatches =
-            record.videoId == null || record.videoId === videoId
+            !record.videoId || record.videoId === videoId
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 56b4b1a and d4bef18.

📒 Files selected for processing (2)
  • apis/api-media/schema.graphql
  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/base.mdc)

**/*.{ts,tsx,js,jsx}: Use early returns whenever possible to make the code more readable.
Use descriptive variable and function/const names.
Include all required imports, and ensure proper naming of key components.

Files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/base.mdc)

Define a type if possible.

Files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
🧠 Learnings (9)
📚 Learning: 2025-12-19T04:58:24.460Z
Learnt from: CR
Repo: JesusFilm/core PR: 0
File: apps/watch/AGENTS.md:0-0
Timestamp: 2025-12-19T04:58:24.460Z
Learning: Applies to apps/watch/src/**/*.{ts,tsx} : Preserve existing contracts in components like `VideoBlock` which depend on the full provider stack, video.js, and mux metadata so autoplay, subtitles, and analytics remain intact.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-12-19T04:58:24.460Z
Learnt from: CR
Repo: JesusFilm/core PR: 0
File: apps/watch/AGENTS.md:0-0
Timestamp: 2025-12-19T04:58:24.460Z
Learning: Applies to apps/watch/src/**/*.{ts,tsx} : Apollo hooks should use generated types alongside colocated documents. Reference the pattern of `useVideoChildren` (`apps/watch/src/libs/useVideoChildren/useVideoChildren.ts`) for data fetching.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-11-11T23:22:02.196Z
Learnt from: mikeallisonJS
Repo: JesusFilm/core PR: 8156
File: apis/api-journeys-modern/src/lib/google/googleAuth.ts:0-0
Timestamp: 2025-11-11T23:22:02.196Z
Learning: In apis/api-journeys-modern, use the validated `env` object from `../../env` instead of accessing `process.env` directly for environment variables that are defined in env.ts (e.g., GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, INTEGRATION_ACCESS_KEY_ENCRYPTION_SECRET). This eliminates the need for runtime validation checks since Zod validates them at application startup.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-04-23T18:26:44.096Z
Learnt from: mikeallisonJS
Repo: JesusFilm/core PR: 6358
File: apis/api-journeys/db/seeds/playwrightUserAccess.ts:16-53
Timestamp: 2025-04-23T18:26:44.096Z
Learning: For seeding scripts in the JesusFilm/core repository, environment variables should be validated and the code should throw an error if required variables are missing rather than silently continuing with fallbacks or filtering.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-12-19T04:58:24.460Z
Learnt from: CR
Repo: JesusFilm/core PR: 0
File: apps/watch/AGENTS.md:0-0
Timestamp: 2025-12-19T04:58:24.460Z
Learning: Applies to apps/watch/src/**/*.{ts,tsx} : REST-like endpoints should use SWR hooks paired with zod guards for response validation; parse responses before returning them to callers.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-05-22T02:57:46.179Z
Learnt from: Kneesal
Repo: JesusFilm/core PR: 6734
File: apps/journeys-admin/src/components/TermsAndConditions/TermsAndConditions.tsx:58-71
Timestamp: 2025-05-22T02:57:46.179Z
Learning: The team prefers to avoid try/catch blocks when working with Apollo Client mutations in favor of Apollo's built-in error handling mechanisms (checking the returned errors property).

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-07-10T22:50:12.252Z
Learnt from: tataihono
Repo: JesusFilm/core PR: 7153
File: apis/api-journeys-modern/src/schema/journey/simple/getSimpleJourney.ts:13-21
Timestamp: 2025-07-10T22:50:12.252Z
Learning: Prisma's `findUnique` method returns `null` when no record is found, rather than throwing an error. The "not found" case should be handled by checking for null, not with try-catch blocks.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-09-29T23:03:36.840Z
Learnt from: mikeallisonJS
Repo: JesusFilm/core PR: 7629
File: apis/api-journeys-modern/src/schema/event/utils.ts:43-60
Timestamp: 2025-09-29T23:03:36.840Z
Learning: In the JesusFilm/core repository, do not recommend using Prisma's `upsert` operation for `JourneyVisitor` creation in `apis/api-journeys-modern/src/schema/event/utils.ts` as it is not race condition safe for this use case. The current `findUnique` then `create` pattern is the preferred approach.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-08-18T17:23:02.876Z
Learnt from: tanflem
Repo: JesusFilm/core PR: 7464
File: apis/api-media/src/workers/processVideoUploads/service/service.ts:300-303
Timestamp: 2025-08-18T17:23:02.876Z
Learning: In the Video GraphQL schema, the slug field is defined as nullable: false with a resolver that returns slug ?? '', meaning it will never be null but could be an empty string if the underlying data is null/undefined.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: affected (22)
  • GitHub Check: lint (22)
  • GitHub Check: test (22, 3/3)
  • GitHub Check: test (22, 1/3)
  • GitHub Check: test (22, 2/3)
  • GitHub Check: build (22)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (6)
apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts (4)

14-28: LGTM!

The error handling utility is well-structured with appropriate fallbacks for different error types.


30-79: LGTM!

The GraphQL type definitions are properly structured and align with the schema changes.


250-270: LGTM!

The mutation properly validates video existence before triggering the Algolia update.


271-330: Well-implemented batch update with comprehensive error handling.

The use of Promise.allSettled ensures all variants are attempted even if some fail, and the error aggregation provides clear feedback about which variants failed. The error message preview limiting to 10 variants is a nice touch for readability.

apis/api-media/schema.graphql (2)

49-66: LGTM!

The new GraphQL types for Algolia validation are well-structured and properly aligned with the TypeScript implementation. The nullability annotations correctly reflect the implementation's behavior.


356-357: LGTM!

The new mutations and queries provide a clean API for Algolia troubleshooting. The required videoId argument and non-null return types are appropriate for these operations.

Also applies to: 749-750

@github-actions github-actions bot temporarily deployed to Preview - resources January 8, 2026 18:29 Inactive
@github-actions github-actions bot temporarily deployed to Preview - journeys-admin January 8, 2026 18:29 Inactive
@github-actions github-actions bot temporarily deployed to Preview - player January 8, 2026 18:29 Inactive
@github-actions github-actions bot temporarily deployed to Preview - videos-admin January 8, 2026 18:29 Inactive
@github-actions github-actions bot temporarily deployed to Preview - short-links January 8, 2026 18:29 Inactive
@github-actions github-actions bot temporarily deployed to Preview - journeys January 8, 2026 18:29 Inactive
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts (4)

107-107: Clarify the hardcoded languageId.

The hardcoded '529' for primary variant selection appears intentional but lacks context. Is this the English language ID? Consider adding a comment or extracting to a named constant.

♻️ Suggested refactor
+// Language ID for English (primary variant)
+const PRIMARY_VARIANT_LANGUAGE_ID = '529'
+
 builder.queryFields((t) => ({
   checkVideoInAlgolia: t.withAuth({ isPublisher: true }).field({
     ...
           variants: {
             select: {
               hls: true,
               lengthInMilliseconds: true,
               downloadable: true
             },
-            where: { languageId: '529' },
+            where: { languageId: PRIMARY_VARIANT_LANGUAGE_ID },
             take: 1
           }

223-239: Performance: Parallelize variant checks.

Sequential Algolia API calls could be slow for videos with many variants. The updateVideoVariantAlgoliaIndex mutation uses Promise.allSettled for parallel execution—consider applying the same pattern here.

♻️ Proposed refactor using Promise.allSettled
-      for (const variant of variants) {
-        try {
-          const record = await client.getObject({
-            indexName: algoliaConfig.videoVariantsIndex,
-            objectID: variant.id
-          })
-          const objectIdMatches = record.objectID === variant.id
-          const videoIdMatches =
-            record.videoId == null || record.videoId === videoId
-
-          if (!(objectIdMatches && videoIdMatches)) {
-            missingVariants.push(variant.id)
-          }
-        } catch {
-          missingVariants.push(variant.id)
-        }
-      }
+      const results = await Promise.allSettled(
+        variants.map(async (variant) => {
+          const record = await client.getObject({
+            indexName: algoliaConfig.videoVariantsIndex,
+            objectID: variant.id
+          })
+          const objectIdMatches = record.objectID === variant.id
+          const videoIdMatches =
+            record.videoId == null || record.videoId === videoId
+
+          if (!(objectIdMatches && videoIdMatches)) {
+            return { missing: true, variantId: variant.id }
+          }
+          return { missing: false, variantId: variant.id }
+        })
+      )
+
+      results.forEach((result) => {
+        if (result.status === 'rejected' || 
+            (result.status === 'fulfilled' && result.value.missing)) {
+          const variantId = result.status === 'fulfilled' 
+            ? result.value.variantId 
+            : variants.find(v => v.id)?.id
+          if (variantId != null) {
+            missingVariants.push(variantId)
+          }
+        }
+      })

236-238: Add error logging for debugging.

The silent catch makes it difficult to diagnose why variants are marked as missing. Consider logging errors similar to the updateVideoVariantAlgoliaIndex mutation (lines 309-312).

♻️ Proposed logging addition
-        } catch {
+        } catch (err) {
+          logger?.error(
+            { err, variantId: variant.id, videoId },
+            'Failed to check variant in Algolia'
+          )
           missingVariants.push(variant.id)
         }

267-268: Consider error handling for consistency.

Unlike updateVideoVariantAlgoliaIndex (lines 289-327), this mutation doesn't catch errors from updateVideoInAlgolia. While GraphQL will handle propagation, consider adding a try-catch to enrich errors with context (e.g., videoId) for better debugging.

♻️ Optional error enrichment
+      try {
         await updateVideoInAlgolia(videoId)
-        return true
+      } catch (err) {
+        logger?.error(
+          { err, videoId },
+          'Failed to update video in Algolia'
+        )
+        throw new GraphQLError(
+          `Failed to update video ${videoId} in Algolia: ${getErrorString(err)}`
+        )
+      }
+      return true
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d4bef18 and 4bf216e.

📒 Files selected for processing (1)
  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/base.mdc)

**/*.{ts,tsx,js,jsx}: Use early returns whenever possible to make the code more readable.
Use descriptive variable and function/const names.
Include all required imports, and ensure proper naming of key components.

Files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/base.mdc)

Define a type if possible.

Files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
🧠 Learnings (10)
📚 Learning: 2025-12-19T04:58:24.460Z
Learnt from: CR
Repo: JesusFilm/core PR: 0
File: apps/watch/AGENTS.md:0-0
Timestamp: 2025-12-19T04:58:24.460Z
Learning: Applies to apps/watch/src/**/*.{ts,tsx} : Preserve existing contracts in components like `VideoBlock` which depend on the full provider stack, video.js, and mux metadata so autoplay, subtitles, and analytics remain intact.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-12-19T04:58:24.460Z
Learnt from: CR
Repo: JesusFilm/core PR: 0
File: apps/watch/AGENTS.md:0-0
Timestamp: 2025-12-19T04:58:24.460Z
Learning: Applies to apps/watch/src/**/*.{ts,tsx} : Apollo hooks should use generated types alongside colocated documents. Reference the pattern of `useVideoChildren` (`apps/watch/src/libs/useVideoChildren/useVideoChildren.ts`) for data fetching.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-12-19T19:18:43.790Z
Learnt from: CR
Repo: JesusFilm/core PR: 0
File: apps/resources/AGENTS.md:0-0
Timestamp: 2025-12-19T19:18:43.790Z
Learning: Apollo hooks should use generated types alongside colocated documents. `useVideoChildren` (`apps/resources/src/libs/useVideoChildren/useVideoChildren.ts`) is the reference pattern

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-11-11T23:22:02.196Z
Learnt from: mikeallisonJS
Repo: JesusFilm/core PR: 8156
File: apis/api-journeys-modern/src/lib/google/googleAuth.ts:0-0
Timestamp: 2025-11-11T23:22:02.196Z
Learning: In apis/api-journeys-modern, use the validated `env` object from `../../env` instead of accessing `process.env` directly for environment variables that are defined in env.ts (e.g., GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, INTEGRATION_ACCESS_KEY_ENCRYPTION_SECRET). This eliminates the need for runtime validation checks since Zod validates them at application startup.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-04-23T18:26:44.096Z
Learnt from: mikeallisonJS
Repo: JesusFilm/core PR: 6358
File: apis/api-journeys/db/seeds/playwrightUserAccess.ts:16-53
Timestamp: 2025-04-23T18:26:44.096Z
Learning: For seeding scripts in the JesusFilm/core repository, environment variables should be validated and the code should throw an error if required variables are missing rather than silently continuing with fallbacks or filtering.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-12-19T04:58:24.460Z
Learnt from: CR
Repo: JesusFilm/core PR: 0
File: apps/watch/AGENTS.md:0-0
Timestamp: 2025-12-19T04:58:24.460Z
Learning: Applies to apps/watch/src/**/*.{ts,tsx} : REST-like endpoints should use SWR hooks paired with zod guards for response validation; parse responses before returning them to callers.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-05-22T02:57:46.179Z
Learnt from: Kneesal
Repo: JesusFilm/core PR: 6734
File: apps/journeys-admin/src/components/TermsAndConditions/TermsAndConditions.tsx:58-71
Timestamp: 2025-05-22T02:57:46.179Z
Learning: The team prefers to avoid try/catch blocks when working with Apollo Client mutations in favor of Apollo's built-in error handling mechanisms (checking the returned errors property).

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-07-10T22:50:12.252Z
Learnt from: tataihono
Repo: JesusFilm/core PR: 7153
File: apis/api-journeys-modern/src/schema/journey/simple/getSimpleJourney.ts:13-21
Timestamp: 2025-07-10T22:50:12.252Z
Learning: Prisma's `findUnique` method returns `null` when no record is found, rather than throwing an error. The "not found" case should be handled by checking for null, not with try-catch blocks.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-09-29T23:03:36.840Z
Learnt from: mikeallisonJS
Repo: JesusFilm/core PR: 7629
File: apis/api-journeys-modern/src/schema/event/utils.ts:43-60
Timestamp: 2025-09-29T23:03:36.840Z
Learning: In the JesusFilm/core repository, do not recommend using Prisma's `upsert` operation for `JourneyVisitor` creation in `apis/api-journeys-modern/src/schema/event/utils.ts` as it is not race condition safe for this use case. The current `findUnique` then `create` pattern is the preferred approach.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
📚 Learning: 2025-08-18T17:23:02.876Z
Learnt from: tanflem
Repo: JesusFilm/core PR: 7464
File: apis/api-media/src/workers/processVideoUploads/service/service.ts:300-303
Timestamp: 2025-08-18T17:23:02.876Z
Learning: In the Video GraphQL schema, the slug field is defined as nullable: false with a resolver that returns slug ?? '', meaning it will never be null but could be an empty string if the underlying data is null/undefined.

Applied to files:

  • apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build (22)
  • GitHub Check: lint (22)
🔇 Additional comments (3)
apis/api-media/src/schema/video/videoAlgolia/videoAlgolia.ts (3)

14-28: LGTM: Comprehensive error conversion.

The fallback chain handles Error objects, strings, JSON serialization, and finally String() conversion effectively.


30-79: LGTM: Well-structured GraphQL types.

The type definitions correctly expose the necessary fields with appropriate nullability constraints.


271-331: LGTM: Excellent error handling and parallel execution.

The use of Promise.allSettled for parallel updates combined with detailed failure reporting (including preview limiting) makes this robust and debuggable.

…roubleshooting' of https://github.com/JesusFilm/core into tannerfleming/vmt-189-backend-video-managment-algolia-troubleshooting
@github-actions github-actions bot temporarily deployed to Preview - journeys January 14, 2026 18:50 Inactive
@github-actions github-actions bot temporarily deployed to Preview - journeys-admin January 14, 2026 18:50 Inactive
@github-actions github-actions bot temporarily deployed to Preview - resources January 14, 2026 18:50 Inactive
@github-actions github-actions bot temporarily deployed to Preview - short-links January 14, 2026 18:50 Inactive
@github-actions github-actions bot temporarily deployed to Preview - videos-admin January 14, 2026 18:50 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants