diff --git a/db/migrations/1709622091352-Data.js b/db/migrations/1709622091352-Data.js new file mode 100644 index 000000000..b850e96e0 --- /dev/null +++ b/db/migrations/1709622091352-Data.js @@ -0,0 +1,11 @@ +module.exports = class Data1709622091352 { + name = 'Data1709622091352' + + async up(db) { + await db.query(`ALTER TABLE "admin"."video" ADD "is_short_derived" boolean`) + } + + async down(db) { + await db.query(`ALTER TABLE "admin"."video" DROP COLUMN "is_short_derived"`) + } +} diff --git a/db/migrations/1708791754135-Views.js b/db/migrations/1709622091505-Views.js similarity index 91% rename from db/migrations/1708791754135-Views.js rename to db/migrations/1709622091505-Views.js index f2e538d6d..85fc1841c 100644 --- a/db/migrations/1708791754135-Views.js +++ b/db/migrations/1709622091505-Views.js @@ -1,7 +1,8 @@ + const { getViewDefinitions } = require('../viewDefinitions') -module.exports = class Views1708791754135 { - name = 'Views1708791754135' +module.exports = class Views1709622091505 { + name = 'Views1709622091505' async up(db) { const viewDefinitions = getViewDefinitions(db); diff --git a/db/migrations/2200000000000-Indexes.js b/db/migrations/2200000000000-Indexes.js index 70fb4024c..652d1a957 100644 --- a/db/migrations/2200000000000-Indexes.js +++ b/db/migrations/2200000000000-Indexes.js @@ -49,6 +49,12 @@ module.exports = class Indexes2200000000000 { await db.query( `CREATE INDEX video_include_in_home_feed_idx ON admin.video (include_in_home_feed) WHERE include_in_home_feed = true;` ) + await db.query( + `CREATE INDEX idx_video_is_short_false ON admin.video (is_short) WHERE is_short = FALSE;` + ) + await db.query( + `CREATE INDEX idx_video_is_short_derived_false ON admin.video (is_short_derived) WHERE is_short_derived = FALSE;` + ) } async down(db) { diff --git a/schema/videos.graphql b/schema/videos.graphql index 8a5714840..e12794391 100644 --- a/schema/videos.graphql +++ b/schema/videos.graphql @@ -130,6 +130,9 @@ type Video @entity @schema(name: "admin") { "Whether the video is a short format, vertical video (e.g. Youtube Shorts, TikTok, Instagram Reels)" isShort: Boolean + "Whether the video is a short format, vertical video, and it derived based on video dimension (i.e. was not set in metadata)" + isShortDerived: Boolean + "Optional boolean flag to indicate if the video should be included in the home feed/page." includeInHomeFeed: Boolean } diff --git a/src/mappings/content/metadata.ts b/src/mappings/content/metadata.ts index f0e0b640e..8fc777666 100644 --- a/src/mappings/content/metadata.ts +++ b/src/mappings/content/metadata.ts @@ -169,6 +169,18 @@ export async function processVideoMetadata( if (isSet(meta.enableComments)) { video.isCommentSectionEnabled = meta.enableComments } + + // Prepare video `isShortDerived` flag + if ( + !isSet(meta.isShort) && + isSet(meta.mediaPixelWidth) && + isSet(meta.mediaPixelHeight) && + meta.mediaPixelHeight > meta.mediaPixelWidth && + meta.duration && + meta.duration <= 60 + ) { + video.isShortDerived = true + } } function extractVideoSize(assets: Flat[]): bigint | undefined {