Skip to content

Commit

Permalink
add is short derived field to video entity (#310)
Browse files Browse the repository at this point in the history
* add is shirt derived field to video entity

* add indices on is short fields
  • Loading branch information
zeeshanakram3 authored Mar 5, 2024
1 parent a597dbd commit 3127350
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
11 changes: 11 additions & 0 deletions db/migrations/1709622091352-Data.js
Original file line number Diff line number Diff line change
@@ -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"`)
}
}
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
6 changes: 6 additions & 0 deletions db/migrations/2200000000000-Indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions schema/videos.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions src/mappings/content/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StorageDataObject>[]): bigint | undefined {
Expand Down

0 comments on commit 3127350

Please sign in to comment.