Don't add a LIMIT 1 to prevent seq scan

pull/6026/head
Chocobozzz 2023-10-26 08:36:53 +02:00
parent d3dd952cc5
commit dd7de7e32d
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 2 additions and 1 deletions

View File

@ -139,7 +139,8 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi
})
static doesInfohashExist (infoHash: string) {
const query = 'SELECT 1 FROM "videoStreamingPlaylist" WHERE "p2pMediaLoaderInfohashes" @> $infoHash LIMIT 1'
// Don't add a LIMIT 1 here to prevent seq scan by PostgreSQL (not sure why id doesn't use the index when we add a LIMIT)
const query = 'SELECT 1 FROM "videoStreamingPlaylist" WHERE "p2pMediaLoaderInfohashes" @> $infoHash'
return doesExist(this.sequelize, query, { infoHash: `{${infoHash}}` }) // Transform infoHash in a PG array
}