From 3127350d73a001dcd271a4b0880861f1adf28525 Mon Sep 17 00:00:00 2001 From: Zeeshan Akram <37098720+zeeshanakram3@users.noreply.github.com> Date: Tue, 5 Mar 2024 17:16:23 +0500 Subject: [PATCH] add is short derived field to video entity (#310) * add is shirt derived field to video entity * add indices on is short fields --- db/migrations/1709622091352-Data.js | 11 +++++++++++ ...1708791754135-Views.js => 1709622091505-Views.js} | 5 +++-- db/migrations/2200000000000-Indexes.js | 6 ++++++ schema/videos.graphql | 3 +++ src/mappings/content/metadata.ts | 12 ++++++++++++ 5 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 db/migrations/1709622091352-Data.js rename db/migrations/{1708791754135-Views.js => 1709622091505-Views.js} (91%) 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 {