Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Optimize infohash SQL query

Chocobozzz82813e973954
diff --git a/server/core/models/video/video-streaming-playlist.ts b/server/core/models/video/video-streaming-playlist.ts
index 0c4043c448..e7f889031b 100644
--- a/server/core/models/video/video-streaming-playlist.ts
+++ b/server/core/models/video/video-streaming-playlist.ts
@@ -139,9 +139,9 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi
})
static doesInfohashExist (infoHash: string) {
- const query = 'SELECT 1 FROM "videoStreamingPlaylist" WHERE $infoHash = ANY("p2pMediaLoaderInfohashes") LIMIT 1'
+ const query = 'SELECT 1 FROM "videoStreamingPlaylist" WHERE "p2pMediaLoaderInfohashes" @> $infoHash LIMIT 1'
- return doesExist(this.sequelize, query, { infoHash })
+ return doesExist(this.sequelize, query, { infoHash: `{${infoHash}}` }) // Transform infoHash in a PG array
}
static buildP2PMediaLoaderInfoHashes (playlistUrl: string, files: unknown[]) {