diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2019-04-12 01:52:25 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2019-04-12 01:52:25 +0900 |
| commit | 2ff3069d23aa688cea5a3bd204236f2f2f64c201 (patch) | |
| tree | 479448f49c2204e5729ed28a1af34a86e354492b /src/remote/activitypub/models | |
| parent | トランザクションを使用してアンケートレコードの挿入... (diff) | |
| download | sharkey-2ff3069d23aa688cea5a3bd204236f2f2f64c201.tar.gz sharkey-2ff3069d23aa688cea5a3bd204236f2f2f64c201.tar.bz2 sharkey-2ff3069d23aa688cea5a3bd204236f2f2f64c201.zip | |
トランザクションを使うようにしたり
Diffstat (limited to 'src/remote/activitypub/models')
| -rw-r--r-- | src/remote/activitypub/models/person.ts | 71 |
1 files changed, 37 insertions, 34 deletions
diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts index b2edf39734..58aca48eb0 100644 --- a/src/remote/activitypub/models/person.ts +++ b/src/remote/activitypub/models/person.ts @@ -25,6 +25,7 @@ import { isDuplicateKeyValueError } from '../../../misc/is-duplicate-key-value-e import { toPuny } from '../../../misc/convert-host'; import { UserProfile } from '../../../models/entities/user-profile'; import { validActor } from '../../../remote/activitypub/type'; +import { getConnection } from 'typeorm'; const logger = apLogger; /** @@ -136,27 +137,42 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us // Create user let user: IRemoteUser; try { - user = await Users.save({ - id: genId(), - avatarId: null, - bannerId: null, - createdAt: Date.parse(person.published) || new Date(), - lastFetchedAt: new Date(), - name: person.name, - isLocked: person.manuallyApprovesFollowers, - username: person.preferredUsername, - usernameLower: person.preferredUsername.toLowerCase(), - host, - inbox: person.inbox, - sharedInbox: person.sharedInbox || (person.endpoints ? person.endpoints.sharedInbox : undefined), - featured: person.featured, - endpoints: person.endpoints, - uri: person.id, - url: person.url, - tags, - isBot, - isCat: (person as any).isCat === true - } as Partial<User>) as IRemoteUser; + // Start transaction + await getConnection().transaction(async transactionalEntityManager => { + user = await transactionalEntityManager.save(new User({ + id: genId(), + avatarId: null, + bannerId: null, + createdAt: new Date(person.published) || new Date(), + lastFetchedAt: new Date(), + name: person.name, + isLocked: person.manuallyApprovesFollowers, + username: person.preferredUsername, + usernameLower: person.preferredUsername.toLowerCase(), + host, + inbox: person.inbox, + sharedInbox: person.sharedInbox || (person.endpoints ? person.endpoints.sharedInbox : undefined), + featured: person.featured, + uri: person.id, + tags, + isBot, + isCat: (person as any).isCat === true + })) as IRemoteUser; + + await transactionalEntityManager.save(new UserProfile({ + userId: user.id, + description: fromHtml(person.summary), + url: person.url, + fields, + userHost: host + })); + + await transactionalEntityManager.save(new UserPublickey({ + userId: user.id, + keyId: person.publicKey.id, + keyPem: person.publicKey.publicKeyPem + })); + }); } catch (e) { // duplicate key error if (isDuplicateKeyValueError(e)) { @@ -167,19 +183,6 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us throw e; } - await UserProfiles.save({ - userId: user.id, - description: fromHtml(person.summary), - fields, - userHost: host - } as Partial<UserProfile>); - - await UserPublickeys.save({ - userId: user.id, - keyId: person.publicKey.id, - keyPem: person.publicKey.publicKeyPem - } as UserPublickey); - // Register host registerOrFetchInstanceDoc(host).then(i => { Instances.increment({ id: i.id }, 'usersCount', 1); |