1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-11-27 22:38:30 +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 }, {
datasize: true,
_id: false
})
.toArray();
});
// Calculate drive usage (in byte)
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 }
}, {
followee_id: true
})
.toArray();
});
// ID list of other users who the I follows
const myfollowingIds = myfollowing.map(follow => follow.followee_id);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,12 +16,11 @@ module.exports = (params, user) =>
new Promise(async (res, rej) =>
{
// Fetch all files to calculate drive usage
const files = await DriveFile
.find({ user_id: user._id }, {
datasize: true,
_id: false
})
.toArray();
const files = await DriveFile
.find({ user_id: user._id }, {
datasize: true,
_id: false
});
// Calculate drive usage (in byte)
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,
sort: sort
})
.toArray();
});
// Serialize
res(await Promise.all(files.map(async file =>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -59,11 +59,10 @@ module.exports = (params, user) =>
// Issue query
const history = await Signin
.find(query, {}, {
.find(query, {
limit: limit,
sort: sort
})
.toArray();
});
// Serialize
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 serialize from '../../serializers/user';
import event from '../../event';
import config from '../../../conf';
/**
* Update myself
@ -73,9 +74,7 @@ module.exports = async (params, user, _, isSecure) =>
user.banner_id = new mongo.ObjectID(banner);
}
await User.updateOne({ _id: user._id }, {
$set: user
});
await User.update(user._id, user);
// Serialize
const iObj = await serialize(user, user, {

View File

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

View File

@ -90,11 +90,10 @@ module.exports = (params, user) =>
// Issue query
const messages = await Message
.find(query, {}, {
.find(query, {
limit: limit,
sort: sort
})
.toArray();
});
// Serialize
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,
partner: recipient._id
}, {
@ -138,7 +138,7 @@ module.exports = (params, user) =>
});
// 履歴作成(相手)
History.updateOne({
History.update({
user_id: recipient._id,
partner: user._id
}, {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -73,11 +73,10 @@ module.exports = (params, user) =>
// Issue query
const reposts = await Post
.find(query, {}, {
.find(query, {
limit: limit,
sort: sort
})
.toArray();
});
// Serialize
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,
skip: offset
})
.toArray();
});
// Serialize
res(await Promise.all(posts.map(async post =>
@ -120,12 +119,11 @@ async function byElasticsearch(res, rej, me, query, offset, max) {
_id: {
$in: hits
}
}, {}, {
}, {
sort: {
_id: -1
}
})
.toArray();
});
posts.map(post => {
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
const timeline = await Post
.find(query, {}, {
.find(query, {
limit: limit,
sort: sort
})
.toArray();
});
// Serialize
res(await Promise.all(timeline.map(async post =>

View File

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

View File

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

View File

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

View File

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

View File

@ -46,14 +46,13 @@ module.exports = (params, me) =>
_id: {
$nin: followingIds
}
}, {}, {
}, {
limit: limit,
skip: offset,
sort: {
followers_count: -1
}
})
.toArray();
});
// Serialize
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)
}]
})
.toArray();
});
// Serialize
res(await Promise.all(users.map(async user =>
@ -106,8 +105,7 @@ async function byElasticsearch(res, rej, me, query, offset, max) {
_id: {
$in: hits
}
})
.toArray();
});
// Serialize
res(await Promise.all(users.map(async user =>

View File

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