トランザクションを使うようにしたり

This commit is contained in:
syuilo
2019-04-12 01:52:25 +09:00
parent 4198246351
commit 2ff3069d23
12 changed files with 117 additions and 67 deletions

View File

@ -12,6 +12,7 @@ import { User } from '../../../models/entities/user';
import { UserKeypair } from '../../../models/entities/user-keypair';
import { toPuny } from '../../../misc/convert-host';
import { UserProfile } from '../../../models/entities/user-profile';
import { getConnection } from 'typeorm';
export default async (ctx: Koa.BaseContext) => {
const body = ctx.request.body as any;
@ -99,28 +100,33 @@ export default async (ctx: Koa.BaseContext) => {
e ? j(e) : s([publicKey, privateKey])
));
const account = await Users.save({
id: genId(),
createdAt: new Date(),
username: username,
usernameLower: username.toLowerCase(),
host: toPuny(host),
token: secret,
isAdmin: config.autoAdmin && usersCount === 0,
} as User);
let account: User;
await UserKeypairs.save({
publicKey: keyPair[0],
privateKey: keyPair[1],
userId: account.id
} as UserKeypair);
// Start transaction
await getConnection().transaction(async transactionalEntityManager => {
account = await transactionalEntityManager.save(new User({
id: genId(),
createdAt: new Date(),
username: username,
usernameLower: username.toLowerCase(),
host: toPuny(host),
token: secret,
isAdmin: config.autoAdmin && usersCount === 0,
}));
await UserProfiles.save({
userId: account.id,
autoAcceptFollowed: true,
autoWatch: false,
password: hash,
} as Partial<UserProfile>);
await transactionalEntityManager.save(new UserKeypair({
publicKey: keyPair[0],
privateKey: keyPair[1],
userId: account.id
}));
await transactionalEntityManager.save(new UserProfile({
userId: account.id,
autoAcceptFollowed: true,
autoWatch: false,
password: hash,
}));
});
usersChart.update(account, true);

View File

@ -16,7 +16,7 @@ import fetchMeta from '../../misc/fetch-meta';
import * as pkg from '../../../package.json';
import { genOpenapiSpec } from '../api/openapi/gen-spec';
import config from '../../config';
import { Users, Notes, Emojis } from '../../models';
import { Users, Notes, Emojis, UserProfiles } from '../../models';
import parseAcct from '../../misc/acct/parse';
import getNoteSummary from '../../misc/get-note-summary';
@ -149,11 +149,14 @@ router.get('/@:user', async (ctx, next) => {
usernameLower: username.toLowerCase(),
host
});
const profile = await UserProfiles.findOne({
userId: user.id
});
if (user != null) {
const meta = await fetchMeta();
await ctx.render('user', {
user,
user, profile,
instanceName: meta.name || 'Misskey'
});
ctx.set('Cache-Control', 'public, max-age=180');

View File

@ -9,12 +9,12 @@ block title
= `${title} | ${instanceName}`
block desc
meta(name='description' content= user.description)
meta(name='description' content= profile.description)
block og
meta(property='og:type' content='blog')
meta(property='og:title' content= title)
meta(property='og:description' content= user.description)
meta(property='og:description' content= profile.description)
meta(property='og:url' content= url)
meta(property='og:image' content= img)
@ -24,12 +24,12 @@ block meta
meta(name='twitter:card' content='summary')
if user.twitter
meta(name='twitter:creator' content=`@${user.twitter.screenName}`)
if profile.twitter
meta(name='twitter:creator' content=`@${profile.twitter.screenName}`)
if !user.host
link(rel='alternate' href=`${config.url}/users/${user._id}` type='application/activity+json')
link(rel='alternate' href=`${config.url}/users/${user.id}` type='application/activity+json')
if user.uri
link(rel='alternate' href=user.uri type='application/activity+json')
if user.url
link(rel='alternate' href=user.url type='text/html')
if profile.url
link(rel='alternate' href=profile.url type='text/html')