0
0
This commit is contained in:
syuilo 2018-06-16 10:40:53 +09:00
parent f164661ef2
commit e11f547308
8 changed files with 102 additions and 22 deletions

11
CHANGELOG.md Normal file
View File

@ -0,0 +1,11 @@
ChangeLog
=========
3.0.0
-----
### Migration
起動する前に、`node cli/recount-stats`してください。
Please run `node cli/recount-stats` before launch.

42
cli/recount-stats.js Normal file
View File

@ -0,0 +1,42 @@
const { default: Note } = require('../built/models/note');
const { default: Meta } = require('../built/models/meta');
const { default: User } = require('../built/models/user');
async function main() {
const meta = await Meta.findOne({});
const notesCount = await Note.count();
const usersCount = await User.count();
const originalNotesCount = await Note.count({
'_user.host': null
});
const originalUsersCount = await User.count({
host: null
});
const stats = {
notesCount,
usersCount,
originalNotesCount,
originalUsersCount
};
if (meta) {
await Meta.update({}, {
$set: {
stats
}
});
} else {
await Meta.insert({
stats
});
}
}
main().then(() => {
console.log('done');
}).catch(console.error);

View File

@ -1,7 +1,7 @@
{ {
"name": "misskey", "name": "misskey",
"author": "syuilo <i@syuilo.com>", "author": "syuilo <i@syuilo.com>",
"version": "2.42.0", "version": "3.0.0",
"clientVersion": "1.0.6517", "clientVersion": "1.0.6517",
"codename": "nighthike", "codename": "nighthike",
"main": "./built/index.js", "main": "./built/index.js",

View File

@ -5,4 +5,10 @@ export default Meta;
export type IMeta = { export type IMeta = {
broadcasts: any[]; broadcasts: any[];
stats: {
notesCount: number;
originalNotesCount: number;
usersCount: number;
originalUsersCount: number;
};
}; };

View File

@ -10,6 +10,7 @@ import Resolver from '../resolver';
import { resolveImage } from './image'; import { resolveImage } from './image';
import { isCollectionOrOrderedCollection, IObject, IPerson } from '../type'; import { isCollectionOrOrderedCollection, IObject, IPerson } from '../type';
import { IDriveFile } from '../../../models/drive-file'; import { IDriveFile } from '../../../models/drive-file';
import Meta from '../../../models/meta';
const log = debug('misskey:activitypub'); const log = debug('misskey:activitypub');
@ -117,6 +118,14 @@ export async function createPerson(value: any, resolver?: Resolver): Promise<IUs
throw e; throw e;
} }
//#region Increment users count
Meta.update({}, {
$inc: {
'stats.usersCount': 1
}
}, { upsert: true });
//#endregion
//#region アイコンとヘッダー画像をフェッチ //#region アイコンとヘッダー画像をフェッチ
const [avatar, banner] = (await Promise.all<IDriveFile>([ const [avatar, banner] = (await Promise.all<IDriveFile>([
person.icon, person.icon,

View File

@ -1,26 +1,10 @@
import Note from '../../../models/note'; import Meta from '../../../models/meta';
import User from '../../../models/user';
/** /**
* Get the misskey's statistics * Get the misskey's statistics
*/ */
module.exports = params => new Promise(async (res, rej) => { module.exports = () => new Promise(async (res, rej) => {
const notesCount = await Note.count(); const meta = await Meta.findOne();
const usersCount = await User.count(); res(meta.stats);
const originalNotesCount = await Note.count({
'_user.host': null
});
const originalUsersCount = await User.count({
host: null
});
res({
notesCount,
usersCount,
originalNotesCount,
originalUsersCount
});
}); });

View File

@ -5,6 +5,7 @@ import recaptcha = require('recaptcha-promise');
import User, { IUser, validateUsername, validatePassword, pack } from '../../../models/user'; import User, { IUser, validateUsername, validatePassword, pack } from '../../../models/user';
import generateUserToken from '../common/generate-native-user-token'; import generateUserToken from '../common/generate-native-user-token';
import config from '../../../config'; import config from '../../../config';
import Meta from '../../../models/meta';
recaptcha.init({ recaptcha.init({
secret_key: config.recaptcha.secret_key secret_key: config.recaptcha.secret_key
@ -93,6 +94,15 @@ export default async (ctx: Koa.Context) => {
} }
}); });
//#region Increment users count
Meta.update({}, {
$inc: {
'stats.usersCount': 1,
'stats.originalUsersCount': 1
}
}, { upsert: true });
//#endregion
// Response // Response
ctx.body = await pack(account); ctx.body = await pack(account);
}; };

View File

@ -18,6 +18,7 @@ import parse from '../../text/parse';
import { IApp } from '../../models/app'; import { IApp } from '../../models/app';
import UserList from '../../models/user-list'; import UserList from '../../models/user-list';
import resolveUser from '../../remote/resolve-user'; import resolveUser from '../../remote/resolve-user';
import Meta from '../../models/meta';
type Reason = 'reply' | 'quote' | 'mention'; type Reason = 'reply' | 'quote' | 'mention';
@ -167,7 +168,24 @@ export default async (user: IUser, data: {
res(note); res(note);
// Increment notes count //#region Increment notes count
if (isLocalUser(user)) {
Meta.update({}, {
$inc: {
'stats.notesCount': 1,
'stats.originalNotesCount': 1
}
}, { upsert: true });
} else {
Meta.update({}, {
$inc: {
'stats.notesCount': 1
}
}, { upsert: true });
}
//#endregion
// Increment notes count (user)
User.update({ _id: user._id }, { User.update({ _id: user._id }, {
$inc: { $inc: {
notesCount: 1 notesCount: 1