Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
792632d726 | |||
9cac293efc | |||
cd8bfca29c | |||
b5b437b878 | |||
cc2947063a | |||
2864a9027f | |||
e11f547308 |
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1,3 +1,4 @@
|
||||
*.svg -diff -text
|
||||
*.psd -diff -text
|
||||
*.ai -diff -text
|
||||
yarn.lock -diff -text
|
||||
|
11
CHANGELOG.md
Normal file
11
CHANGELOG.md
Normal 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
42
cli/recount-stats.js
Normal 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);
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "misskey",
|
||||
"author": "syuilo <i@syuilo.com>",
|
||||
"version": "2.42.0",
|
||||
"version": "3.0.1",
|
||||
"clientVersion": "1.0.6517",
|
||||
"codename": "nighthike",
|
||||
"main": "./built/index.js",
|
||||
@ -86,9 +86,8 @@
|
||||
"webfinger.js": "2.6.6",
|
||||
"websocket": "1.0.26",
|
||||
"ws": "5.2.0",
|
||||
"xev": "2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"xev": "2.0.1",
|
||||
|
||||
"@prezzemolo/zip": "0.0.3",
|
||||
"@types/bcryptjs": "2.4.1",
|
||||
"@types/debug": "0.0.30",
|
||||
|
@ -5,4 +5,10 @@ export default Meta;
|
||||
|
||||
export type IMeta = {
|
||||
broadcasts: any[];
|
||||
stats: {
|
||||
notesCount: number;
|
||||
originalNotesCount: number;
|
||||
usersCount: number;
|
||||
originalUsersCount: number;
|
||||
};
|
||||
};
|
||||
|
@ -16,7 +16,7 @@ import Following from './following';
|
||||
const Note = db.get<INote>('notes');
|
||||
Note.createIndex('uri', { sparse: true, unique: true });
|
||||
Note.createIndex('userId');
|
||||
Note.createIndex('tags', { sparse: true });
|
||||
Note.createIndex('tagsLower');
|
||||
Note.createIndex({
|
||||
createdAt: -1
|
||||
});
|
||||
@ -40,6 +40,7 @@ export type INote = {
|
||||
poll: any; // todo
|
||||
text: string;
|
||||
tags: string[];
|
||||
tagsLower: string[];
|
||||
cw: string;
|
||||
userId: mongo.ObjectID;
|
||||
appId: mongo.ObjectID;
|
||||
|
@ -10,6 +10,7 @@ import Resolver from '../resolver';
|
||||
import { resolveImage } from './image';
|
||||
import { isCollectionOrOrderedCollection, IObject, IPerson } from '../type';
|
||||
import { IDriveFile } from '../../../models/drive-file';
|
||||
import Meta from '../../../models/meta';
|
||||
|
||||
const log = debug('misskey:activitypub');
|
||||
|
||||
@ -117,6 +118,14 @@ export async function createPerson(value: any, resolver?: Resolver): Promise<IUs
|
||||
throw e;
|
||||
}
|
||||
|
||||
//#region Increment users count
|
||||
Meta.update({}, {
|
||||
$inc: {
|
||||
'stats.usersCount': 1
|
||||
}
|
||||
}, { upsert: true });
|
||||
//#endregion
|
||||
|
||||
//#region アイコンとヘッダー画像をフェッチ
|
||||
const [avatar, banner] = (await Promise.all<IDriveFile>([
|
||||
person.icon,
|
||||
|
@ -7,7 +7,7 @@ import Note from '../../../../models/note';
|
||||
|
||||
const rangeA = 1000 * 60 * 30; // 30分
|
||||
const rangeB = 1000 * 60 * 120; // 2時間
|
||||
const coefficient = 1.5; // 「n倍」の部分
|
||||
const coefficient = 1.25; // 「n倍」の部分
|
||||
const requiredUsers = 3; // 最低何人がそのタグを投稿している必要があるか
|
||||
|
||||
const max = 5;
|
||||
@ -22,20 +22,20 @@ module.exports = () => new Promise(async (res, rej) => {
|
||||
createdAt: {
|
||||
$gt: new Date(Date.now() - rangeA)
|
||||
},
|
||||
tags: {
|
||||
tagsLower: {
|
||||
$exists: true,
|
||||
$ne: []
|
||||
}
|
||||
}
|
||||
}, {
|
||||
$unwind: '$tags'
|
||||
$unwind: '$tagsLower'
|
||||
}, {
|
||||
$group: {
|
||||
_id: { tags: '$tags', userId: '$userId' }
|
||||
_id: { tag: '$tagsLower', userId: '$userId' }
|
||||
}
|
||||
}]) as Array<{
|
||||
_id: {
|
||||
tags: string;
|
||||
tag: string;
|
||||
userId: any;
|
||||
}
|
||||
}>;
|
||||
@ -49,12 +49,12 @@ module.exports = () => new Promise(async (res, rej) => {
|
||||
|
||||
// カウント
|
||||
data.map(x => x._id).forEach(x => {
|
||||
const i = tags.findIndex(tag => tag.name == x.tags);
|
||||
const i = tags.findIndex(tag => tag.name == x.tag);
|
||||
if (i != -1) {
|
||||
tags[i].count++;
|
||||
} else {
|
||||
tags.push({
|
||||
name: x.tags,
|
||||
name: x.tag,
|
||||
count: 1
|
||||
});
|
||||
}
|
||||
@ -66,7 +66,7 @@ module.exports = () => new Promise(async (res, rej) => {
|
||||
//#region 2. 1で取得したそれぞれのタグについて、「直近a分間のユニーク投稿数が今からa分前~今からb分前の間のユニーク投稿数のn倍以上」かどうかを判定する
|
||||
const hotsPromises = limitedTags.map(async tag => {
|
||||
const passedCount = (await Note.distinct('userId', {
|
||||
tags: tag.name,
|
||||
tagsLower: tag.name,
|
||||
createdAt: {
|
||||
$lt: new Date(Date.now() - rangeA),
|
||||
$gt: new Date(Date.now() - rangeB)
|
||||
@ -108,7 +108,7 @@ module.exports = () => new Promise(async (res, rej) => {
|
||||
|
||||
for (let i = 0; i < range; i++) {
|
||||
countPromises.push(Promise.all(hots.map(tag => Note.distinct('userId', {
|
||||
tags: tag,
|
||||
tagsLower: tag,
|
||||
createdAt: {
|
||||
$lt: new Date(Date.now() - (interval * i)),
|
||||
$gt: new Date(Date.now() - (interval * (i + 1)))
|
||||
@ -119,7 +119,7 @@ module.exports = () => new Promise(async (res, rej) => {
|
||||
const countsLog = await Promise.all(countPromises);
|
||||
|
||||
const totalCounts: any = await Promise.all(hots.map(tag => Note.distinct('userId', {
|
||||
tags: tag,
|
||||
tagsLower: tag,
|
||||
createdAt: {
|
||||
$gt: new Date(Date.now() - (interval * range))
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ async function search(
|
||||
|
||||
let q: any = {
|
||||
$and: [{
|
||||
tags: tag
|
||||
tagsLower: tag.toLowerCase()
|
||||
}]
|
||||
};
|
||||
|
||||
|
@ -1,26 +1,10 @@
|
||||
import Note from '../../../models/note';
|
||||
import User from '../../../models/user';
|
||||
import Meta from '../../../models/meta';
|
||||
|
||||
/**
|
||||
* Get the misskey's statistics
|
||||
*/
|
||||
module.exports = params => new Promise(async (res, rej) => {
|
||||
const notesCount = await Note.count();
|
||||
module.exports = () => new Promise(async (res, rej) => {
|
||||
const meta = await Meta.findOne();
|
||||
|
||||
const usersCount = await User.count();
|
||||
|
||||
const originalNotesCount = await Note.count({
|
||||
'_user.host': null
|
||||
});
|
||||
|
||||
const originalUsersCount = await User.count({
|
||||
host: null
|
||||
});
|
||||
|
||||
res({
|
||||
notesCount,
|
||||
usersCount,
|
||||
originalNotesCount,
|
||||
originalUsersCount
|
||||
});
|
||||
res(meta.stats);
|
||||
});
|
||||
|
@ -5,6 +5,7 @@ import recaptcha = require('recaptcha-promise');
|
||||
import User, { IUser, validateUsername, validatePassword, pack } from '../../../models/user';
|
||||
import generateUserToken from '../common/generate-native-user-token';
|
||||
import config from '../../../config';
|
||||
import Meta from '../../../models/meta';
|
||||
|
||||
recaptcha.init({
|
||||
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
|
||||
ctx.body = await pack(account);
|
||||
};
|
||||
|
@ -18,6 +18,7 @@ import parse from '../../text/parse';
|
||||
import { IApp } from '../../models/app';
|
||||
import UserList from '../../models/user-list';
|
||||
import resolveUser from '../../remote/resolve-user';
|
||||
import Meta from '../../models/meta';
|
||||
|
||||
type Reason = 'reply' | 'quote' | 'mention';
|
||||
|
||||
@ -129,6 +130,7 @@ export default async (user: IUser, data: {
|
||||
poll: data.poll,
|
||||
cw: data.cw == null ? null : data.cw,
|
||||
tags,
|
||||
tagsLower: tags.map(tag => tag.toLowerCase()),
|
||||
userId: user._id,
|
||||
viaMobile: data.viaMobile,
|
||||
geo: data.geo || null,
|
||||
@ -167,7 +169,24 @@ export default async (user: IUser, data: {
|
||||
|
||||
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 }, {
|
||||
$inc: {
|
||||
notesCount: 1
|
||||
|
Reference in New Issue
Block a user