Thank you, can you test:
explain analyze SELECT
"video".*,
"VideoChannel"."id" AS "VideoChannel.id",
"VideoChannel"."name" AS "VideoChannel.name",
"VideoChannel"."description" AS "VideoChannel.description",
"VideoChannel"."accountId" AS "VideoChannel.accountId",
"VideoChannel->Actor"."id" AS "VideoChannel.Actor.id",
"VideoChannel->Actor"."preferredUsername" AS "VideoChannel.Actor.preferredUsername",
"VideoChannel->Actor"."url" AS "VideoChannel.Actor.url",
"VideoChannel->Actor"."serverId" AS "VideoChannel.Actor.serverId",
"VideoChannel->Actor"."accountId" AS "VideoChannel.Actor.accountId",
"VideoChannel->Actor"."videoChannelId" AS "VideoChannel.Actor.videoChannelId",
"VideoChannel->Actor->Avatars"."id" AS "VideoChannel.Actor.Avatars.id",
"VideoChannel->Actor->Avatars"."width" AS "VideoChannel.Actor.Avatars.width",
"VideoChannel->Actor->Avatars"."filename" AS "VideoChannel.Actor.Avatars.filename",
"VideoChannel->Actor->Avatars"."type" AS "VideoChannel.Actor.Avatars.type",
"VideoChannel->Actor->Avatars"."fileUrl" AS "VideoChannel.Actor.Avatars.fileUrl",
"VideoChannel->Actor->Avatars"."cached" AS "VideoChannel.Actor.Avatars.cached",
"VideoChannel->Actor->Avatars"."createdAt" AS "VideoChannel.Actor.Avatars.createdAt",
"VideoChannel->Actor->Avatars"."updatedAt" AS "VideoChannel.Actor.Avatars.updatedAt",
"VideoChannel->Actor->Server"."id" AS "VideoChannel.Actor.Server.id",
"VideoChannel->Actor->Server"."host" AS "VideoChannel.Actor.Server.host",
"VideoChannel->Account"."id" AS "VideoChannel.Account.id",
"VideoChannel->Account"."name" AS "VideoChannel.Account.name",
"VideoChannel->Account->Actor"."id" AS "VideoChannel.Account.Actor.id",
"VideoChannel->Account->Actor"."preferredUsername" AS "VideoChannel.Account.Actor.preferredUsername",
"VideoChannel->Account->Actor"."url" AS "VideoChannel.Account.Actor.url",
"VideoChannel->Account->Actor"."serverId" AS "VideoChannel.Account.Actor.serverId",
"VideoChannel->Account->Actor"."accountId" AS "VideoChannel.Account.Actor.accountId",
"VideoChannel->Account->Actor"."videoChannelId" AS "VideoChannel.Account.Actor.videoChannelId",
"VideoChannel->Account->Actor->Avatars"."id" AS "VideoChannel.Account.Actor.Avatars.id",
"VideoChannel->Account->Actor->Avatars"."width" AS "VideoChannel.Account.Actor.Avatars.width",
"VideoChannel->Account->Actor->Avatars"."filename" AS "VideoChannel.Account.Actor.Avatars.filename",
"VideoChannel->Account->Actor->Avatars"."type" AS "VideoChannel.Account.Actor.Avatars.type",
"VideoChannel->Account->Actor->Avatars"."fileUrl" AS "VideoChannel.Account.Actor.Avatars.fileUrl",
"VideoChannel->Account->Actor->Avatars"."cached" AS "VideoChannel.Account.Actor.Avatars.cached",
"VideoChannel->Account->Actor->Avatars"."createdAt" AS "VideoChannel.Account.Actor.Avatars.createdAt",
"VideoChannel->Account->Actor->Avatars"."updatedAt" AS "VideoChannel.Account.Actor.Avatars.updatedAt",
"VideoChannel->Account->Actor->Server"."id" AS "VideoChannel.Account.Actor.Server.id",
"VideoChannel->Account->Actor->Server"."host" AS "VideoChannel.Account.Actor.Server.host",
"Thumbnails"."id" AS "Thumbnails.id",
"Thumbnails"."filename" AS "Thumbnails.filename",
"Thumbnails"."height" AS "Thumbnails.height",
"Thumbnails"."width" AS "Thumbnails.width",
"Thumbnails"."fileUrl" AS "Thumbnails.fileUrl"
FROM
(
WITH "videoCandidates" AS (
SELECT
"videoShare"."videoId"
FROM
"videoShare"
WHERE
"videoShare"."actorId" IN (
SELECT
"targetActorId"
FROM
"actorFollow"
WHERE
"actorFollow"."actorId" = 1
AND "actorFollow"."state" = 'accepted'
)
UNION
SELECT
"video"."id"
FROM
"video"
INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId"
INNER JOIN "actor" "channelActor" ON "videoChannel"."id" = "channelActor"."videoChannelId"
WHERE
"channelActor"."id" IN (
SELECT
"targetActorId"
FROM
"actorFollow"
WHERE
"actorFollow"."actorId" = 1
AND "actorFollow"."state" = 'accepted'
)
UNION
SELECT
"video"."id"
FROM
"video"
INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId"
INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId"
INNER JOIN "actor" "accountActor" ON "account"."id" = "accountActor"."accountId"
WHERE
"accountActor"."id" IN (
SELECT
"targetActorId"
FROM
"actorFollow"
WHERE
"actorFollow"."actorId" = 1
AND "actorFollow"."state" = 'accepted'
)
UNION
SELECT
"video"."id"
FROM
"video"
WHERE
"remote" IS FALSE
)
SELECT
"video"."id",
LOG(GREATEST(1, "video"."likes" - 1)) * 150 + LOG(GREATEST(1, "video"."dislikes" - 1)) * -150 + LOG("video"."views" + 1) * 16 + LOG(GREATEST(1, "video"."comments")) * 100 + (
SELECT
(
EXTRACT(
epoch
FROM
"video"."publishedAt"
) - 1446156582
) / 47000
) AS "score",
0 as similarity
FROM
"video"
INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId"
INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId"
INNER JOIN "actor" "accountActor" ON "account"."id" = "accountActor"."accountId"
INNER JOIN "videoCandidates" ON "video"."id" = "videoCandidates"."videoId"
WHERE
"video"."id" NOT IN (
SELECT
"videoBlacklist"."videoId"
FROM
"videoBlacklist"
)
AND NOT EXISTS (
SELECT
1
FROM
"accountBlocklist"
WHERE
"accountBlocklist"."accountId" IN ('1')
AND "accountBlocklist"."targetAccountId" = "account"."id"
)
AND NOT EXISTS (
SELECT
1
FROM
"serverBlocklist"
WHERE
"serverBlocklist"."accountId" IN ('1')
AND "serverBlocklist"."targetServerId" = "accountActor"."serverId"
)
AND (
"video"."state" = 1
OR (
"video"."state" = 2
AND "video"."waitTranscoding" IS false
)
)
AND "video"."privacy" = 1
AND "video"."isLive" IS FALSE
ORDER BY
"score" DESC,
"video"."views" DESC
LIMIT
25 OFFSET 0
) AS "tmp"
INNER JOIN "video" ON "tmp"."id" = "video"."id"
INNER JOIN "videoChannel" AS "VideoChannel" ON "video"."channelId" = "VideoChannel"."id"
INNER JOIN "actor" AS "VideoChannel->Actor" ON "VideoChannel"."id" = "VideoChannel->Actor"."videoChannelId"
LEFT OUTER JOIN "server" AS "VideoChannel->Actor->Server" ON "VideoChannel->Actor"."serverId" = "VideoChannel->Actor->Server"."id"
LEFT OUTER JOIN "actorImage" AS "VideoChannel->Actor->Avatars" ON "VideoChannel->Actor"."id" = "VideoChannel->Actor->Avatars"."actorId"
AND "VideoChannel->Actor->Avatars"."type" = 1
INNER JOIN "account" AS "VideoChannel->Account" ON "VideoChannel"."accountId" = "VideoChannel->Account"."id"
INNER JOIN "actor" AS "VideoChannel->Account->Actor" ON "VideoChannel->Account"."id" = "VideoChannel->Account->Actor"."accountId"
LEFT OUTER JOIN "server" AS "VideoChannel->Account->Actor->Server" ON "VideoChannel->Account->Actor"."serverId" = "VideoChannel->Account->Actor->Server"."id"
LEFT OUTER JOIN "actorImage" AS "VideoChannel->Account->Actor->Avatars" ON "VideoChannel->Account->Actor"."id" = "VideoChannel->Account->Actor->Avatars"."actorId"
AND "VideoChannel->Account->Actor->Avatars"."type" = 1
LEFT OUTER JOIN "thumbnail" AS "Thumbnails" ON "video"."id" = "Thumbnails"."videoId"
ORDER BY
"score" DESC,
"video"."views" DESC