テーブル分割

This commit is contained in:
syuilo
2019-04-10 15:04:27 +09:00
parent 9603f3fa4f
commit 626cfb61ac
33 changed files with 267 additions and 232 deletions

View File

@ -14,16 +14,16 @@ import { IIdentifier } from './identifier';
import { apLogger } from '../logger';
import { Note } from '../../../models/entities/note';
import { updateHashtag } from '../../../services/update-hashtag';
import { Users, UserNotePinings, Instances, DriveFiles, Followings, UserServiceLinkings, UserPublickeys } from '../../../models';
import { Users, UserNotePinings, Instances, DriveFiles, Followings, UserProfiles, UserPublickeys } from '../../../models';
import { User, IRemoteUser } from '../../../models/entities/user';
import { Emoji } from '../../../models/entities/emoji';
import { UserNotePining } from '../../../models/entities/user-note-pinings';
import { genId } from '../../../misc/gen-id';
import { UserServiceLinking } from '../../../models/entities/user-service-linking';
import { instanceChart, usersChart } from '../../../services/chart';
import { UserPublickey } from '../../../models/entities/user-publickey';
import { isDuplicateKeyValueError } from '../../../misc/is-duplicate-key-value-error';
import { toPuny } from '../../../misc/convert-host';
import { UserProfile } from '../../../models/entities/user-profile';
const logger = apLogger;
/**
@ -126,7 +126,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
const host = toPuny(new URL(object.id).hostname);
const { fields, services } = analyzeAttachments(person.attachment);
const { fields } = analyzeAttachments(person.attachment);
const tags = extractHashtags(person.tag).map(tag => tag.toLowerCase());
@ -141,7 +141,6 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
bannerId: null,
createdAt: Date.parse(person.published) || new Date(),
lastFetchedAt: new Date(),
description: fromHtml(person.summary),
name: person.name,
isLocked: person.manuallyApprovesFollowers,
username: person.preferredUsername,
@ -153,8 +152,6 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
endpoints: person.endpoints,
uri: person.id,
url: person.url,
fields,
...services,
tags,
isBot,
isCat: (person as any).isCat === true
@ -169,18 +166,18 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
throw e;
}
await UserProfiles.save({
userId: user.id,
description: fromHtml(person.summary),
fields,
} as Partial<UserProfile>);
await UserPublickeys.save({
id: genId(),
userId: user.id,
keyId: person.publicKey.id,
keyPem: person.publicKey.publicKeyPem
} as UserPublickey);
await UserServiceLinkings.save({
id: genId(),
userId: user.id
} as UserServiceLinking);
// Register host
registerOrFetchInstanceDoc(host).then(i => {
Instances.increment({ id: i.id }, 'usersCount', 1);
@ -347,7 +344,7 @@ export async function updatePerson(uri: string, resolver?: Resolver, hint?: obje
keyPem: person.publicKey.publicKeyPem
});
await UserServiceLinkings.update({ userId: exist.id }, {
await UserProfiles.update({ userId: exist.id }, {
twitterUserId: services.twitter.userId,
twitterScreenName: services.twitter.screenName,
githubId: services.github.id,

View File

@ -8,15 +8,15 @@ import { getEmojis } from './note';
import renderEmoji from './emoji';
import { IIdentifier } from '../models/identifier';
import renderHashtag from './hashtag';
import { DriveFiles, UserServiceLinkings, UserKeypairs } from '../../../models';
import { DriveFiles, UserProfiles, UserKeypairs } from '../../../models';
export async function renderPerson(user: ILocalUser) {
const id = `${config.url}/users/${user.id}`;
const [avatar, banner, links] = await Promise.all([
const [avatar, banner, profile] = await Promise.all([
DriveFiles.findOne(user.avatarId),
DriveFiles.findOne(user.bannerId),
UserServiceLinkings.findOne({ userId: user.id })
UserProfiles.findOne({ userId: user.id })
]);
const attachment: {
@ -27,41 +27,41 @@ export async function renderPerson(user: ILocalUser) {
identifier?: IIdentifier
}[] = [];
if (links.twitter) {
if (profile.twitter) {
attachment.push({
type: 'PropertyValue',
name: 'Twitter',
value: `<a href="https://twitter.com/intent/user?user_id=${links.twitterUserId}" rel="me nofollow noopener" target="_blank"><span>@${links.twitterScreenName}</span></a>`,
value: `<a href="https://twitter.com/intent/user?user_id=${profile.twitterUserId}" rel="me nofollow noopener" target="_blank"><span>@${profile.twitterScreenName}</span></a>`,
identifier: {
type: 'PropertyValue',
name: 'misskey:authentication:twitter',
value: `${links.twitterUserId}@${links.twitterScreenName}`
value: `${profile.twitterUserId}@${profile.twitterScreenName}`
}
});
}
if (links.github) {
if (profile.github) {
attachment.push({
type: 'PropertyValue',
name: 'GitHub',
value: `<a href="https://github.com/${links.githubLogin}" rel="me nofollow noopener" target="_blank"><span>@${links.githubLogin}</span></a>`,
value: `<a href="https://github.com/${profile.githubLogin}" rel="me nofollow noopener" target="_blank"><span>@${profile.githubLogin}</span></a>`,
identifier: {
type: 'PropertyValue',
name: 'misskey:authentication:github',
value: `${links.githubId}@${links.githubLogin}`
value: `${profile.githubId}@${profile.githubLogin}`
}
});
}
if (links.discord) {
if (profile.discord) {
attachment.push({
type: 'PropertyValue',
name: 'Discord',
value: `<a href="https://discordapp.com/users/${links.discordId}" rel="me nofollow noopener" target="_blank"><span>${links.discordUsername}#${links.discordDiscriminator}</span></a>`,
value: `<a href="https://discordapp.com/users/${profile.discordId}" rel="me nofollow noopener" target="_blank"><span>${profile.discordUsername}#${profile.discordDiscriminator}</span></a>`,
identifier: {
type: 'PropertyValue',
name: 'misskey:authentication:discord',
value: `${links.discordId}@${links.discordUsername}#${links.discordDiscriminator}`
value: `${profile.discordId}@${profile.discordUsername}#${profile.discordDiscriminator}`
}
});
}
@ -93,7 +93,7 @@ export async function renderPerson(user: ILocalUser) {
url: `${config.url}/@${user.username}`,
preferredUsername: user.username,
name: user.name,
summary: toHtml(parse(user.description)),
summary: toHtml(parse(profile.description)),
icon: user.avatarId && renderImage(avatar),
image: user.bannerId && renderImage(banner),
tag,