1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-12-03 01:08:57 +09:00
This commit is contained in:
syuilo 2017-01-17 11:11:22 +09:00
parent caa8aee7a0
commit 9f81288fcc
48 changed files with 91 additions and 140 deletions

View File

@ -72,8 +72,7 @@ export default (
.find({ user_id: user._id }, { .find({ user_id: user._id }, {
datasize: true, datasize: true,
_id: false _id: false
}) });
.toArray();
// Calculate drive usage (in byte) // Calculate drive usage (in byte)
const usage = files.map(file => file.datasize).reduce((x, y) => x + y, 0); const usage = files.map(file => file.datasize).reduce((x, y) => x + y, 0);

View File

@ -11,8 +11,7 @@ export default async (me: mongodb.ObjectID, includeMe: boolean = true) => {
deleted_at: { $exists: false } deleted_at: { $exists: false }
}, { }, {
followee_id: true followee_id: true
}) });
.toArray();
// ID list of other users who the I follows // ID list of other users who the I follows
const myfollowingIds = myfollowing.map(follow => follow.followee_id); const myfollowingIds = myfollowing.map(follow => follow.followee_id);

View File

@ -48,8 +48,7 @@ module.exports = (params) =>
_id: '$date', _id: '$date',
count: { $sum: 1 } count: { $sum: 1 }
}} }}
]) ]);
.toArray();
datas.forEach(data => { datas.forEach(data => {
data.date = data._id; data.date = data._id;

View File

@ -45,8 +45,7 @@ module.exports = (params) =>
post_id: false post_id: false
}, { }, {
sort: { created_at: -1 } sort: { created_at: -1 }
}) });
.toArray();
const graph = []; const graph = [];

View File

@ -47,8 +47,7 @@ module.exports = (params) =>
_id: '$date', _id: '$date',
count: { $sum: 1 } count: { $sum: 1 }
}} }}
]) ]);
.toArray();
datas.forEach(data => { datas.forEach(data => {
data.date = data._id; data.date = data._id;

View File

@ -47,8 +47,7 @@ module.exports = (params) =>
_id: '$date', _id: '$date',
count: { $sum: 1 } count: { $sum: 1 }
}} }}
]) ]);
.toArray();
datas.forEach(data => { datas.forEach(data => {
data.date = data._id; data.date = data._id;

View File

@ -46,8 +46,7 @@ module.exports = (params) =>
followee_id: false followee_id: false
}, { }, {
sort: { created_at: -1 } sort: { created_at: -1 }
}) });
.toArray();
const graph = []; const graph = [];

View File

@ -46,8 +46,7 @@ module.exports = (params) =>
followee_id: false followee_id: false
}, { }, {
sort: { created_at: -1 } sort: { created_at: -1 }
}) });
.toArray();
const graph = []; const graph = [];

View File

@ -48,8 +48,7 @@ module.exports = (params) =>
_id: '$date', _id: '$date',
count: { $sum: 1 } count: { $sum: 1 }
}} }}
]) ]);
.toArray();
datas.forEach(data => { datas.forEach(data => {
data.date = data._id; data.date = data._id;

View File

@ -70,8 +70,7 @@ module.exports = (params) =>
count: '$count' count: '$count'
}} }}
} } } }
]) ]);
.toArray();
datas.forEach(data => { datas.forEach(data => {
data.date = data._id; data.date = data._id;

View File

@ -87,12 +87,8 @@ module.exports = (params, user) =>
} }
// Update session // Update session
await AuthSess.updateOne({ await AuthSess.update(session._id, {
_id: session._id
}, {
$set: {
user_id: user._id user_id: user._id
}
}); });
// Response // Response

View File

@ -20,8 +20,7 @@ module.exports = (params, user) =>
.find({ user_id: user._id }, { .find({ user_id: user._id }, {
datasize: true, datasize: true,
_id: false _id: false
}) });
.toArray();
// Calculate drive usage (in byte) // Calculate drive usage (in byte)
const usage = files.map(file => file.datasize).reduce((x, y) => x + y, 0); const usage = files.map(file => file.datasize).reduce((x, y) => x + y, 0);

View File

@ -73,8 +73,7 @@ module.exports = (params, user, app) =>
}, { }, {
limit: limit, limit: limit,
sort: sort sort: sort
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(files.map(async file => res(await Promise.all(files.map(async file =>

View File

@ -39,8 +39,7 @@ module.exports = (params, user) =>
folder_id: folder folder_id: folder
}, { }, {
data: false data: false
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(files.map(async file => res(await Promise.all(files.map(async file =>

View File

@ -74,9 +74,7 @@ module.exports = (params, user) =>
} }
} }
DriveFile.updateOne({ _id: file._id }, { DriveFile.update(file._id, file);
$set: file
});
// Serialize // Serialize
const fileObj = await serialize(file); const fileObj = await serialize(file);

View File

@ -73,8 +73,7 @@ module.exports = (params, user, app) =>
}, { }, {
limit: limit, limit: limit,
sort: sort sort: sort
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(folders.map(async folder => res(await Promise.all(folders.map(async folder =>

View File

@ -37,8 +37,7 @@ module.exports = (params, user) =>
name: name, name: name,
user_id: user._id, user_id: user._id,
parent_id: parentId parent_id: parentId
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(folders.map(async folder => res(await Promise.all(folders.map(async folder =>

View File

@ -99,9 +99,7 @@ module.exports = (params, user) =>
} }
// Update // Update
DriveFolder.updateOne({ _id: folder._id }, { DriveFolder.update(folder._id, folder);
$set: folder
});
// Serialize // Serialize
const folderObj = await serialize(folder); const folderObj = await serialize(folder);

View File

@ -76,8 +76,7 @@ module.exports = (params, user) =>
}, { }, {
limit: limit, limit: limit,
sort: sort sort: sort
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(files.map(async file => res(await Promise.all(files.map(async file =>

View File

@ -64,14 +64,14 @@ module.exports = (params, user) =>
res(); res();
// Increment following count // Increment following count
User.updateOne({ _id: follower._id }, { User.update(follower._id, {
$inc: { $inc: {
following_count: 1 following_count: 1
} }
}); });
// Increment followers count // Increment followers count
User.updateOne({ _id: followee._id }, { User.update({ _id: followee._id }, {
$inc: { $inc: {
followers_count: 1 followers_count: 1
} }

View File

@ -53,7 +53,7 @@ module.exports = (params, user) =>
} }
// Delete following // Delete following
await Following.updateOne({ await Following.update({
_id: exist._id _id: exist._id
}, { }, {
$set: { $set: {
@ -65,14 +65,14 @@ module.exports = (params, user) =>
res(); res();
// Decrement following count // Decrement following count
User.updateOne({ _id: follower._id }, { User.update({ _id: follower._id }, {
$inc: { $inc: {
following_count: -1 following_count: -1
} }
}); });
// Decrement followers count // Decrement followers count
User.updateOne({ _id: followee._id }, { User.update({ _id: followee._id }, {
$inc: { $inc: {
followers_count: -1 followers_count: -1
} }

View File

@ -29,7 +29,7 @@ module.exports = (params, user, app, isSecure) =>
data: Object.assign(user.data || {}, JSON.parse(data)) data: Object.assign(user.data || {}, JSON.parse(data))
} }
}; };
await User.updateOne({ _id: user._id }, set); await User.update({ _id: user._id }, set);
res(204); res(204);
} else { } else {
const appdata = await Appdata.findOne({ const appdata = await Appdata.findOne({
@ -41,7 +41,7 @@ module.exports = (params, user, app, isSecure) =>
data: Object.assign((appdata || {}).data || {}, JSON.parse(data)) data: Object.assign((appdata || {}).data || {}, JSON.parse(data))
} }
}; };
await Appdata.updateOne({ await Appdata.update({
app_id: app._id, app_id: app._id,
user_id: user._id user_id: user._id
}, Object.assign({ }, Object.assign({

View File

@ -44,14 +44,13 @@ module.exports = (params) =>
const favorites = await Favorites const favorites = await Favorites
.find({ .find({
user_id: user._id user_id: user._id
}, {}, { }, {
limit: limit, limit: limit,
skip: offset, skip: offset,
sort: { sort: {
_id: sort == 'asc' ? 1 : -1 _id: sort == 'asc' ? 1 : -1
} }
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(favorites.map(async favorite => res(await Promise.all(favorites.map(async favorite =>

View File

@ -92,11 +92,10 @@ module.exports = (params, user) =>
// Issue query // Issue query
const notifications = await Notification const notifications = await Notification
.find(query, {}, { .find(query, {
limit: limit, limit: limit,
sort: sort sort: sort
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(notifications.map(async notification => res(await Promise.all(notifications.map(async notification =>

View File

@ -59,11 +59,10 @@ module.exports = (params, user) =>
// Issue query // Issue query
const history = await Signin const history = await Signin
.find(query, {}, { .find(query, {
limit: limit, limit: limit,
sort: sort sort: sort
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(history.map(async record => res(await Promise.all(history.map(async record =>

View File

@ -8,6 +8,7 @@ import User from '../../models/user';
import { isValidBirthday } from '../../models/user'; import { isValidBirthday } from '../../models/user';
import serialize from '../../serializers/user'; import serialize from '../../serializers/user';
import event from '../../event'; import event from '../../event';
import config from '../../../conf';
/** /**
* Update myself * Update myself
@ -73,9 +74,7 @@ module.exports = async (params, user, _, isSecure) =>
user.banner_id = new mongo.ObjectID(banner); user.banner_id = new mongo.ObjectID(banner);
} }
await User.updateOne({ _id: user._id }, { await User.update(user._id, user);
$set: user
});
// Serialize // Serialize
const iObj = await serialize(user, user, { const iObj = await serialize(user, user, {

View File

@ -34,13 +34,12 @@ module.exports = (params, user) =>
const history = await History const history = await History
.find({ .find({
user_id: user._id user_id: user._id
}, {}, { }, {
limit: limit, limit: limit,
sort: { sort: {
updated_at: -1 updated_at: -1
} }
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(history.map(async h => res(await Promise.all(history.map(async h =>

View File

@ -90,11 +90,10 @@ module.exports = (params, user) =>
// Issue query // Issue query
const messages = await Message const messages = await Message
.find(query, {}, { .find(query, {
limit: limit, limit: limit,
sort: sort sort: sort
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(messages.map(async message => res(await Promise.all(messages.map(async message =>

View File

@ -125,7 +125,7 @@ module.exports = (params, user) =>
} }
// 履歴作成(自分) // 履歴作成(自分)
History.updateOne({ History.update({
user_id: user._id, user_id: user._id,
partner: recipient._id partner: recipient._id
}, { }, {
@ -138,7 +138,7 @@ module.exports = (params, user) =>
}); });
// 履歴作成(相手) // 履歴作成(相手)
History.updateOne({ History.update({
user_id: recipient._id, user_id: recipient._id,
partner: user._id partner: user._id
}, { }, {

View File

@ -44,14 +44,13 @@ module.exports = (params, user) =>
// Execute query // Execute query
const apps = await App const apps = await App
.find(query, {}, { .find(query, {
limit: limit, limit: limit,
skip: offset, skip: offset,
sort: { sort: {
created_at: -1 created_at: -1
} }
}) });
.toArray();
// Reply // Reply
res(await Promise.all(apps.map(async app => res(await Promise.all(apps.map(async app =>

View File

@ -37,7 +37,7 @@ module.exports = (params, user) =>
// Update // Update
notification.is_read = true; notification.is_read = true;
Notification.updateOne({ _id: notification._id }, { Notification.update({ _id: notification._id }, {
$set: { $set: {
is_read: true is_read: true
} }

View File

@ -54,11 +54,10 @@ module.exports = (params) =>
// Issue query // Issue query
const posts = await Post const posts = await Post
.find(query, {}, { .find(query, {
limit: limit, limit: limit,
sort: sort sort: sort
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(posts.map(async post => await serialize(post)))); res(await Promise.all(posts.map(async post => await serialize(post))));

View File

@ -13,6 +13,7 @@ import serialize from '../../serializers/post';
import createFile from '../../common/add-file-to-drive'; import createFile from '../../common/add-file-to-drive';
import notify from '../../common/notify'; import notify from '../../common/notify';
import event from '../../event'; import event from '../../event';
import config from '../../../conf';
/** /**
* 最大文字数 * 最大文字数
@ -103,7 +104,7 @@ module.exports = (params, user, app) =>
// Fetch recently post // Fetch recently post
const latestPost = await Post.findOne({ const latestPost = await Post.findOne({
user_id: user._id user_id: user._id
}, {}, { }, {
sort: { sort: {
_id: -1 _id: -1
} }
@ -152,7 +153,7 @@ module.exports = (params, user, app) =>
} }
// 投稿を作成 // 投稿を作成
const inserted = await Post.insert({ const post = await Post.insert({
created_at: new Date(), created_at: new Date(),
media_ids: media ? files.map(file => file._id) : undefined, media_ids: media ? files.map(file => file._id) : undefined,
reply_to_id: replyTo ? replyTo._id : undefined, reply_to_id: replyTo ? replyTo._id : undefined,
@ -162,8 +163,6 @@ module.exports = (params, user, app) =>
app_id: app ? app._id : null app_id: app ? app._id : null
}); });
const post = inserted.ops[0];
// Serialize // Serialize
const postObj = await serialize(post); const postObj = await serialize(post);
@ -200,15 +199,14 @@ module.exports = (params, user, app) =>
}, { }, {
follower_id: true, follower_id: true,
_id: false _id: false
}) });
.toArray();
// Publish event to followers stream // Publish event to followers stream
followers.forEach(following => followers.forEach(following =>
event(following.follower_id, 'post', postObj)); event(following.follower_id, 'post', postObj));
// Increment my posts count // Increment my posts count
User.updateOne({ _id: user._id }, { User.update({ _id: user._id }, {
$inc: { $inc: {
posts_count: 1 posts_count: 1
} }
@ -217,7 +215,7 @@ module.exports = (params, user, app) =>
// If has in reply to post // If has in reply to post
if (replyTo) { if (replyTo) {
// Increment replies count // Increment replies count
Post.updateOne({ _id: replyTo._id }, { Post.update({ _id: replyTo._id }, {
$inc: { $inc: {
replies_count: 1 replies_count: 1
} }
@ -262,7 +260,7 @@ module.exports = (params, user, app) =>
if (!existRepost) { if (!existRepost) {
// Update repostee status // Update repostee status
Post.updateOne({ _id: repost._id }, { Post.update({ _id: repost._id }, {
$inc: { $inc: {
repost_count: 1 repost_count: 1
} }
@ -336,7 +334,7 @@ module.exports = (params, user, app) =>
// Append mentions data // Append mentions data
if (mentions.length > 0) { if (mentions.length > 0) {
Post.updateOne({ _id: post._id }, { Post.update({ _id: post._id }, {
$set: { $set: {
mentions: mentions mentions: mentions
} }

View File

@ -62,14 +62,13 @@ module.exports = (params, user) =>
.find({ .find({
post_id: post._id, post_id: post._id,
deleted_at: { $exists: false } deleted_at: { $exists: false }
}, {}, { }, {
limit: limit, limit: limit,
skip: offset, skip: offset,
sort: { sort: {
_id: sort == 'asc' ? 1 : -1 _id: sort == 'asc' ? 1 : -1
} }
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(likes.map(async like => res(await Promise.all(likes.map(async like =>

View File

@ -66,21 +66,21 @@ module.exports = (params, user) =>
res(); res();
// Increment likes count // Increment likes count
Post.updateOne({ _id: post._id }, { Post.update({ _id: post._id }, {
$inc: { $inc: {
likes_count: 1 likes_count: 1
} }
}); });
// Increment user likes count // Increment user likes count
User.updateOne({ _id: user._id }, { User.update({ _id: user._id }, {
$inc: { $inc: {
likes_count: 1 likes_count: 1
} }
}); });
// Increment user liked count // Increment user liked count
User.updateOne({ _id: post.user_id }, { User.update({ _id: post.user_id }, {
$inc: { $inc: {
liked_count: 1 liked_count: 1
} }

View File

@ -46,7 +46,7 @@ module.exports = (params, user) =>
} }
// Delete like // Delete like
await Like.updateOne({ await Like.update({
_id: exist._id _id: exist._id
}, { }, {
$set: { $set: {
@ -58,21 +58,21 @@ module.exports = (params, user) =>
res(); res();
// Decrement likes count // Decrement likes count
Post.updateOne({ _id: post._id }, { Post.update({ _id: post._id }, {
$inc: { $inc: {
likes_count: -1 likes_count: -1
} }
}); });
// Decrement user likes count // Decrement user likes count
User.updateOne({ _id: user._id }, { User.update({ _id: user._id }, {
$inc: { $inc: {
likes_count: -1 likes_count: -1
} }
}); });
// Decrement user liked count // Decrement user liked count
User.updateOne({ _id: post.user_id }, { User.update({ _id: post.user_id }, {
$inc: { $inc: {
liked_count: -1 liked_count: -1
} }

View File

@ -72,11 +72,10 @@ module.exports = (params, user) =>
// Issue query // Issue query
const mentions = await Post const mentions = await Post
.find(query, {}, { .find(query, {
limit: limit, limit: limit,
sort: sort sort: sort
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(mentions.map(async mention => res(await Promise.all(mentions.map(async mention =>

View File

@ -58,14 +58,13 @@ module.exports = (params, user) =>
// Issue query // Issue query
const replies = await Post const replies = await Post
.find({ reply_to_id: post._id }, {}, { .find({ reply_to_id: post._id }, {
limit: limit, limit: limit,
skip: offset, skip: offset,
sort: { sort: {
_id: sort == 'asc' ? 1 : -1 _id: sort == 'asc' ? 1 : -1
} }
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(replies.map(async post => res(await Promise.all(replies.map(async post =>

View File

@ -73,11 +73,10 @@ module.exports = (params, user) =>
// Issue query // Issue query
const reposts = await Post const reposts = await Post
.find(query, {}, { .find(query, {
limit: limit, limit: limit,
sort: sort sort: sort
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(reposts.map(async post => res(await Promise.all(reposts.map(async post =>

View File

@ -65,8 +65,7 @@ async function byNative(res, rej, me, query, offset, max) {
}, },
limit: max, limit: max,
skip: offset skip: offset
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(posts.map(async post => res(await Promise.all(posts.map(async post =>
@ -120,12 +119,11 @@ async function byElasticsearch(res, rej, me, query, offset, max) {
_id: { _id: {
$in: hits $in: hits
} }
}, {}, { }, {
sort: { sort: {
_id: -1 _id: -1
} }
}) });
.toArray();
posts.map(post => { posts.map(post => {
post._highlight = response.hits.hits.filter(hit => post._id.equals(hit._id))[0].highlight.text[0]; post._highlight = response.hits.hits.filter(hit => post._id.equals(hit._id))[0].highlight.text[0];

View File

@ -65,11 +65,10 @@ module.exports = (params, user, app) =>
// Issue query // Issue query
const timeline = await Post const timeline = await Post
.find(query, {}, { .find(query, {
limit: limit, limit: limit,
sort: sort sort: sort
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(timeline.map(async post => res(await Promise.all(timeline.map(async post =>

View File

@ -55,11 +55,10 @@ module.exports = (params, me) =>
// Issue query // Issue query
const users = await User const users = await User
.find(query, {}, { .find(query, {
limit: limit, limit: limit,
sort: sort sort: sort
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(users.map(async user => res(await Promise.all(users.map(async user =>

View File

@ -78,11 +78,10 @@ module.exports = (params, me) =>
// Get followers // Get followers
const following = await Following const following = await Following
.find(query, {}, { .find(query, {
limit: limit + 1, limit: limit + 1,
sort: { _id: -1 } sort: { _id: -1 }
}) });
.toArray();
// 「次のページ」があるかどうか // 「次のページ」があるかどうか
const inStock = following.length === limit + 1; const inStock = following.length === limit + 1;

View File

@ -78,11 +78,10 @@ module.exports = (params, me) =>
// Get followers // Get followers
const following = await Following const following = await Following
.find(query, {}, { .find(query, {
limit: limit + 1, limit: limit + 1,
sort: { _id: -1 } sort: { _id: -1 }
}) });
.toArray();
// 「次のページ」があるかどうか // 「次のページ」があるかどうか
const inStock = following.length === limit + 1; const inStock = following.length === limit + 1;

View File

@ -111,11 +111,10 @@ module.exports = (params, me) =>
// Issue query // Issue query
const posts = await Post const posts = await Post
.find(query, {}, { .find(query, {
limit: limit, limit: limit,
sort: sort sort: sort
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(posts.map(async (post) => res(await Promise.all(posts.map(async (post) =>

View File

@ -46,14 +46,13 @@ module.exports = (params, me) =>
_id: { _id: {
$nin: followingIds $nin: followingIds
} }
}, {}, { }, {
limit: limit, limit: limit,
skip: offset, skip: offset,
sort: { sort: {
followers_count: -1 followers_count: -1
} }
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(users.map(async user => res(await Promise.all(users.map(async user =>

View File

@ -63,8 +63,7 @@ async function byNative(res, rej, me, query, offset, max) {
}, { }, {
name: new RegExp(escapedQuery) name: new RegExp(escapedQuery)
}] }]
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(users.map(async user => res(await Promise.all(users.map(async user =>
@ -106,8 +105,7 @@ async function byElasticsearch(res, rej, me, query, offset, max) {
_id: { _id: {
$in: hits $in: hits
} }
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(users.map(async user => res(await Promise.all(users.map(async user =>

View File

@ -56,8 +56,7 @@ module.exports = (params, me) =>
}, { }, {
limit: limit, limit: limit,
skip: offset skip: offset
}) });
.toArray();
// Serialize // Serialize
res(await Promise.all(users.map(async user => res(await Promise.all(users.map(async user =>