From eb66ee88351a93eb68c366cfbe30d35ed7c57b03 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 9 Jan 2023 10:29:23 +0100 Subject: Refactor table attributes --- .../sql/shared/actor-follow-table-attributes.ts | 65 ++++++---------------- 1 file changed, 17 insertions(+), 48 deletions(-) (limited to 'server/models/actor/sql') diff --git a/server/models/actor/sql/shared/actor-follow-table-attributes.ts b/server/models/actor/sql/shared/actor-follow-table-attributes.ts index 156b37d44..7dd908ece 100644 --- a/server/models/actor/sql/shared/actor-follow-table-attributes.ts +++ b/server/models/actor/sql/shared/actor-follow-table-attributes.ts @@ -1,62 +1,31 @@ +import { logger } from '@server/helpers/logger' +import { Memoize } from '@server/helpers/memoize' +import { ServerModel } from '@server/models/server/server' +import { ActorModel } from '../../actor' +import { ActorFollowModel } from '../../actor-follow' +import { ActorImageModel } from '../../actor-image' + export class ActorFollowTableAttributes { + @Memoize() getFollowAttributes () { - return [ - '"ActorFollowModel"."id"', - '"ActorFollowModel"."state"', - '"ActorFollowModel"."score"', - '"ActorFollowModel"."url"', - '"ActorFollowModel"."actorId"', - '"ActorFollowModel"."targetActorId"', - '"ActorFollowModel"."createdAt"', - '"ActorFollowModel"."updatedAt"' - ].join(', ') + logger.error('coucou') + + return ActorFollowModel.getSQLAttributes('ActorFollowModel').join(', ') } + @Memoize() getActorAttributes (actorTableName: string) { - return [ - `"${actorTableName}"."id" AS "${actorTableName}.id"`, - `"${actorTableName}"."type" AS "${actorTableName}.type"`, - `"${actorTableName}"."preferredUsername" AS "${actorTableName}.preferredUsername"`, - `"${actorTableName}"."url" AS "${actorTableName}.url"`, - `"${actorTableName}"."publicKey" AS "${actorTableName}.publicKey"`, - `"${actorTableName}"."privateKey" AS "${actorTableName}.privateKey"`, - `"${actorTableName}"."followersCount" AS "${actorTableName}.followersCount"`, - `"${actorTableName}"."followingCount" AS "${actorTableName}.followingCount"`, - `"${actorTableName}"."inboxUrl" AS "${actorTableName}.inboxUrl"`, - `"${actorTableName}"."outboxUrl" AS "${actorTableName}.outboxUrl"`, - `"${actorTableName}"."sharedInboxUrl" AS "${actorTableName}.sharedInboxUrl"`, - `"${actorTableName}"."followersUrl" AS "${actorTableName}.followersUrl"`, - `"${actorTableName}"."followingUrl" AS "${actorTableName}.followingUrl"`, - `"${actorTableName}"."remoteCreatedAt" AS "${actorTableName}.remoteCreatedAt"`, - `"${actorTableName}"."serverId" AS "${actorTableName}.serverId"`, - `"${actorTableName}"."createdAt" AS "${actorTableName}.createdAt"`, - `"${actorTableName}"."updatedAt" AS "${actorTableName}.updatedAt"` - ].join(', ') + return ActorModel.getSQLAttributes(actorTableName, `${actorTableName}.`).join(', ') } + @Memoize() getServerAttributes (actorTableName: string) { - return [ - `"${actorTableName}->Server"."id" AS "${actorTableName}.Server.id"`, - `"${actorTableName}->Server"."host" AS "${actorTableName}.Server.host"`, - `"${actorTableName}->Server"."redundancyAllowed" AS "${actorTableName}.Server.redundancyAllowed"`, - `"${actorTableName}->Server"."createdAt" AS "${actorTableName}.Server.createdAt"`, - `"${actorTableName}->Server"."updatedAt" AS "${actorTableName}.Server.updatedAt"` - ].join(', ') + return ServerModel.getSQLAttributes(`${actorTableName}->Server`, `${actorTableName}.Server.`).join(', ') } + @Memoize() getAvatarAttributes (actorTableName: string) { - return [ - `"${actorTableName}->Avatars"."id" AS "${actorTableName}.Avatars.id"`, - `"${actorTableName}->Avatars"."filename" AS "${actorTableName}.Avatars.filename"`, - `"${actorTableName}->Avatars"."height" AS "${actorTableName}.Avatars.height"`, - `"${actorTableName}->Avatars"."width" AS "${actorTableName}.Avatars.width"`, - `"${actorTableName}->Avatars"."fileUrl" AS "${actorTableName}.Avatars.fileUrl"`, - `"${actorTableName}->Avatars"."onDisk" AS "${actorTableName}.Avatars.onDisk"`, - `"${actorTableName}->Avatars"."type" AS "${actorTableName}.Avatars.type"`, - `"${actorTableName}->Avatars"."actorId" AS "${actorTableName}.Avatars.actorId"`, - `"${actorTableName}->Avatars"."createdAt" AS "${actorTableName}.Avatars.createdAt"`, - `"${actorTableName}->Avatars"."updatedAt" AS "${actorTableName}.Avatars.updatedAt"` - ].join(', ') + return ActorImageModel.getSQLAttributes(`${actorTableName}->Avatars`, `${actorTableName}.Avatars.`).join(', ') } } -- cgit v1.2.3