Use PostgreSQL instead of MongoDB (#4572)

* wip

* Update note.ts

* Update timeline.ts

* Update core.ts

* wip

* Update generate-visibility-query.ts

* wip

* wip

* wip

* wip

* wip

* Update global-timeline.ts

* wip

* wip

* wip

* Update vote.ts

* wip

* wip

* Update create.ts

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update files.ts

* wip

* wip

* Update CONTRIBUTING.md

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update read-notification.ts

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update cancel.ts

* wip

* wip

* wip

* Update show.ts

* wip

* wip

* Update gen-id.ts

* Update create.ts

* Update id.ts

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Docker: Update files about Docker (#4599)

* Docker: Use cache if files used by `yarn install` was not updated

This patch reduces the number of times to installing node_modules.
For example, `yarn install` step will be skipped when only ".config/default.yml" is updated.

* Docker: Migrate MongoDB to Postgresql

Misskey uses Postgresql as a database instead of Mongodb since version 11.

* Docker: Uncomment about data persistence

This patch will save a lot of databases.

* wip

* wip

* wip

* Update activitypub.ts

* wip

* wip

* wip

* Update logs.ts

* wip

* Update drive-file.ts

* Update register.ts

* wip

* wip

* Update mentions.ts

* wip

* wip

* wip

* Update recommendation.ts

* wip

* Update index.ts

* wip

* Update recommendation.ts

* Doc: Update docker.ja.md and docker.en.md (#1) (#4608)

Update how to set up misskey.

* wip

* ✌️

* wip

* Update note.ts

* Update postgre.ts

* wip

* wip

* wip

* wip

* Update add-file.ts

* wip

* wip

* wip

* Clean up

* Update logs.ts

* wip

* 🍕

* wip

* Ad notes

* wip

* Update api-visibility.ts

* Update note.ts

* Update add-file.ts

* tests

* tests

* Update postgre.ts

* Update utils.ts

* wip

* wip

* Refactor

* wip

* Refactor

* wip

* wip

* Update show-users.ts

* Update update-instance.ts

* wip

* Update feed.ts

* Update outbox.ts

* Update outbox.ts

* Update user.ts

* wip

* Update list.ts

* Update update-hashtag.ts

* wip

* Update update-hashtag.ts

* Refactor

* Update update.ts

* wip

* wip

* ✌️

* clean up

* docs

* Update push.ts

* wip

* Update api.ts

* wip

* ✌️

* Update make-pagination-query.ts

* ✌️

* Delete hashtags.ts

* Update instances.ts

* Update instances.ts

* Update create.ts

* Update search.ts

* Update reversi-game.ts

* Update signup.ts

* Update user.ts

* id

* Update example.yml

* 🎨

* objectid

* fix

* reversi

* reversi

* Fix bug of chart engine

* Add test of chart engine

* Improve test

* Better testing

* Improve chart engine

* Refactor

* Add test of chart engine

* Refactor

* Add chart test

* Fix bug

* コミットし忘れ

* Refactoring

* ✌️

* Add tests

* Add test

* Extarct note tests

* Refactor

* 存在しないユーザーにメンションできなくなっていた問題を修正

* Fix bug

* Update update-meta.ts

* Fix bug

* Update mention.vue

* Fix bug

* Update meta.ts

* Update CONTRIBUTING.md

* Fix bug

* Fix bug

* Fix bug

* Clean up

* Clean up

* Update notification.ts

* Clean up

* Add mute tests

* Add test

* Refactor

* Add test

* Fix test

* Refactor

* Refactor

* Add tests

* Update utils.ts

* Update utils.ts

* Fix test

* Update package.json

* Update update.ts

* Update manifest.ts

* Fix bug

* Fix bug

* Add test

* 🎨

* Update endpoint permissions

* Updaye permisison

* Update person.ts

#4299

* データベースと同期しないように

* Fix bug

* Fix bug

* Update reversi-game.ts

* Use a feature of Node v11.7.0 to extract a public key (#4644)

* wip

* wip

* ✌️

* Refactoring

#1540

* test

* test

* test

* test

* test

* test

* test

* Fix bug

* Fix test

* 🍣

* wip

* #4471

* Add test for #4335

* Refactor

* Fix test

* Add tests

* 🕓

* Fix bug

* Add test

* Add test

* rename

* Fix bug
This commit is contained in:
syuilo 2019-04-07 21:50:36 +09:00 committed by GitHub
parent 13caf37991
commit f0a29721c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
592 changed files with 13463 additions and 14147 deletions

View file

@ -1,18 +1,16 @@
import $ from 'cafy';
import ID, { transform } from '../../../../misc/cafy-id';
import User, { isValidName, isValidDescription, isValidLocation, isValidBirthday, pack } from '../../../../models/user';
import { ID } from '../../../../misc/cafy-id';
import { publishMainStream } from '../../../../services/stream';
import DriveFile from '../../../../models/drive-file';
import acceptAllFollowRequests from '../../../../services/following/requests/accept-all';
import { publishToFollowers } from '../../../../services/i/update';
import define from '../../define';
import getDriveFileUrl from '../../../../misc/get-drive-file-url';
import { parse, parsePlain } from '../../../../mfm/parse';
import extractEmojis from '../../../../misc/extract-emojis';
import extractHashtags from '../../../../misc/extract-hashtags';
import * as langmap from 'langmap';
import { updateHashtag } from '../../../../services/update-hashtag';
import { ApiError } from '../../error';
import { Users, DriveFiles } from '../../../../models';
export const meta = {
desc: {
@ -24,18 +22,18 @@ export const meta = {
requireCredential: true,
kind: 'account-write',
kind: 'write:account',
params: {
name: {
validator: $.optional.nullable.str.pipe(isValidName),
validator: $.optional.nullable.str.pipe(Users.isValidName),
desc: {
'ja-JP': '名前(ハンドルネームやニックネーム)'
}
},
description: {
validator: $.optional.nullable.str.pipe(isValidDescription),
validator: $.optional.nullable.str.pipe(Users.isValidDescription),
desc: {
'ja-JP': 'アカウントの説明や自己紹介'
}
@ -49,14 +47,14 @@ export const meta = {
},
location: {
validator: $.optional.nullable.str.pipe(isValidLocation),
validator: $.optional.nullable.str.pipe(Users.isValidLocation),
desc: {
'ja-JP': '住んでいる地域、所在'
}
},
birthday: {
validator: $.optional.nullable.str.pipe(isValidBirthday),
validator: $.optional.nullable.str.pipe(Users.isValidBirthday),
desc: {
'ja-JP': '誕生日 (YYYY-MM-DD形式)'
}
@ -64,7 +62,6 @@ export const meta = {
avatarId: {
validator: $.optional.nullable.type(ID),
transform: transform,
desc: {
'ja-JP': 'アイコンに設定する画像のドライブファイルID'
}
@ -72,20 +69,11 @@ export const meta = {
bannerId: {
validator: $.optional.nullable.type(ID),
transform: transform,
desc: {
'ja-JP': 'バナーに設定する画像のドライブファイルID'
}
},
wallpaperId: {
validator: $.optional.nullable.type(ID),
transform: transform,
desc: {
'ja-JP': '壁紙に設定する画像のドライブファイルID'
}
},
isLocked: {
validator: $.optional.bool,
desc: {
@ -171,116 +159,76 @@ export default define(meta, async (ps, user, app) => {
if (ps.name !== undefined) updates.name = ps.name;
if (ps.description !== undefined) updates.description = ps.description;
if (ps.lang !== undefined) updates.lang = ps.lang;
if (ps.location !== undefined) updates['profile.location'] = ps.location;
if (ps.birthday !== undefined) updates['profile.birthday'] = ps.birthday;
if (ps.location !== undefined) updates.location = ps.location;
if (ps.birthday !== undefined) updates.birthday = ps.birthday;
if (ps.avatarId !== undefined) updates.avatarId = ps.avatarId;
if (ps.bannerId !== undefined) updates.bannerId = ps.bannerId;
if (ps.wallpaperId !== undefined) updates.wallpaperId = ps.wallpaperId;
if (typeof ps.isLocked == 'boolean') updates.isLocked = ps.isLocked;
if (typeof ps.isBot == 'boolean') updates.isBot = ps.isBot;
if (typeof ps.carefulBot == 'boolean') updates.carefulBot = ps.carefulBot;
if (typeof ps.autoAcceptFollowed == 'boolean') updates.autoAcceptFollowed = ps.autoAcceptFollowed;
if (typeof ps.isCat == 'boolean') updates.isCat = ps.isCat;
if (typeof ps.autoWatch == 'boolean') updates['settings.autoWatch'] = ps.autoWatch;
if (typeof ps.alwaysMarkNsfw == 'boolean') updates['settings.alwaysMarkNsfw'] = ps.alwaysMarkNsfw;
if (typeof ps.autoWatch == 'boolean') updates.autoWatch = ps.autoWatch;
if (typeof ps.alwaysMarkNsfw == 'boolean') updates.alwaysMarkNsfw = ps.alwaysMarkNsfw;
if (ps.avatarId) {
const avatar = await DriveFile.findOne({
_id: ps.avatarId
});
const avatar = await DriveFiles.findOne(ps.avatarId);
if (avatar == null) throw new ApiError(meta.errors.noSuchAvatar);
if (!avatar.contentType.startsWith('image/')) throw new ApiError(meta.errors.avatarNotAnImage);
if (avatar == null || avatar.userId !== user.id) throw new ApiError(meta.errors.noSuchAvatar);
if (!avatar.type.startsWith('image/')) throw new ApiError(meta.errors.avatarNotAnImage);
if (avatar.metadata.deletedAt) {
updates.avatarUrl = null;
} else {
updates.avatarUrl = getDriveFileUrl(avatar, true);
updates.avatarUrl = avatar.thumbnailUrl;
if (avatar.metadata.properties.avgColor) {
updates.avatarColor = avatar.metadata.properties.avgColor;
}
if (avatar.properties.avgColor) {
updates.avatarColor = avatar.properties.avgColor;
}
}
if (ps.bannerId) {
const banner = await DriveFile.findOne({
_id: ps.bannerId
});
const banner = await DriveFiles.findOne(ps.bannerId);
if (banner == null) throw new ApiError(meta.errors.noSuchBanner);
if (!banner.contentType.startsWith('image/')) throw new ApiError(meta.errors.bannerNotAnImage);
if (banner == null || banner.userId !== user.id) throw new ApiError(meta.errors.noSuchBanner);
if (!banner.type.startsWith('image/')) throw new ApiError(meta.errors.bannerNotAnImage);
if (banner.metadata.deletedAt) {
updates.bannerUrl = null;
} else {
updates.bannerUrl = getDriveFileUrl(banner, false);
updates.bannerUrl = banner.webpublicUrl;
if (banner.metadata.properties.avgColor) {
updates.bannerColor = banner.metadata.properties.avgColor;
}
}
}
if (ps.wallpaperId !== undefined) {
if (ps.wallpaperId === null) {
updates.wallpaperUrl = null;
updates.wallpaperColor = null;
} else {
const wallpaper = await DriveFile.findOne({
_id: ps.wallpaperId
});
if (wallpaper == null) throw new Error('wallpaper not found');
if (wallpaper.metadata.deletedAt) {
updates.wallpaperUrl = null;
} else {
updates.wallpaperUrl = getDriveFileUrl(wallpaper);
if (wallpaper.metadata.properties.avgColor) {
updates.wallpaperColor = wallpaper.metadata.properties.avgColor;
}
}
if (banner.properties.avgColor) {
updates.bannerColor = banner.properties.avgColor;
}
}
//#region emojis/tags
if (updates.name != null || updates.description != null) {
let emojis = [] as string[];
let tags = [] as string[];
let emojis = [] as string[];
let tags = [] as string[];
if (updates.name != null) {
const tokens = parsePlain(updates.name);
emojis = emojis.concat(extractEmojis(tokens));
}
if (updates.description != null) {
const tokens = parse(updates.description);
emojis = emojis.concat(extractEmojis(tokens));
tags = extractHashtags(tokens).map(tag => tag.toLowerCase());
}
updates.emojis = emojis;
updates.tags = tags;
// ハッシュタグ更新
for (const tag of tags) updateHashtag(user, tag, true, true);
for (const tag of (user.tags || []).filter(x => !tags.includes(x))) updateHashtag(user, tag, true, false);
if (updates.name != null) {
const tokens = parsePlain(updates.name);
emojis = emojis.concat(extractEmojis(tokens));
}
if (updates.description != null) {
const tokens = parse(updates.description);
emojis = emojis.concat(extractEmojis(tokens));
tags = extractHashtags(tokens).map(tag => tag.toLowerCase());
}
updates.emojis = emojis;
updates.tags = tags;
// ハッシュタグ更新
for (const tag of tags) updateHashtag(user, tag, true, true);
for (const tag of user.tags.filter(x => !tags.includes(x))) updateHashtag(user, tag, true, false);
//#endregion
await User.update(user._id, {
$set: updates
});
await Users.update(user.id, updates);
const iObj = await pack(user._id, user, {
const iObj = await Users.pack(user.id, user, {
detail: true,
includeSecrets: isSecure
});
// Publish meUpdated event
publishMainStream(user._id, 'meUpdated', iObj);
publishMainStream(user.id, 'meUpdated', iObj);
// 鍵垢を解除したとき、溜まっていたフォローリクエストがあるならすべて承認
if (user.isLocked && ps.isLocked === false) {
@ -288,7 +236,7 @@ export default define(meta, async (ps, user, app) => {
}
// フォロワーにUpdateを配信
publishToFollowers(user._id);
publishToFollowers(user.id);
return iObj;
});