This commit is contained in:
syuilo 2018-08-18 23:48:54 +09:00
parent ef79903811
commit df71c90f9f
6 changed files with 270 additions and 17 deletions

View file

@ -5,6 +5,15 @@ ChangeLog
This document describes breaking changes only. This document describes breaking changes only.
7.0.0
-----
### Migration
起動する前に、`node cli/migration/7.0.0`してください。
Please run `node cli/migration/7.0.0` before launch.
6.0.0 6.0.0
----- -----

134
cli/migration/7.0.0.js Normal file
View file

@ -0,0 +1,134 @@
const { default: Chart } = require('../../built/models/chart');
const { default: User } = require('../../built/models/user');
const { default: Note } = require('../../built/models/note');
const { default: DriveFile } = require('../../built/models/drive-file');
const now = new Date();
const y = now.getFullYear();
const m = now.getMonth();
const d = now.getDate();
const today = new Date(y, m, d);
async function main() {
const localUsersCount = await User.count({
host: null
});
const remoteUsersCount = await User.count({
host: { $ne: null }
});
const localNotesCount = await Note.count({
'_user.host': null
});
const remoteNotesCount = await Note.count({
'_user.host': { $ne: null }
});
const localDriveFilesCount = await DriveFile.count({
'metadata._user.host': null
});
const remoteDriveFilesCount = await DriveFile.count({
'metadata._user.host': { $ne: null }
});
const localDriveFilesSize = await DriveFile
.aggregate([{
$match: {
'metadata._user.host': null,
'metadata.deletedAt': { $exists: false }
}
}, {
$project: {
length: true
}
}, {
$group: {
_id: null,
usage: { $sum: '$length' }
}
}])
.then(aggregates => {
if (aggregates.length > 0) {
return aggregates[0].usage;
}
return 0;
});
const remoteDriveFilesSize = await DriveFile
.aggregate([{
$match: {
'metadata._user.host': { $ne: null },
'metadata.deletedAt': { $exists: false }
}
}, {
$project: {
length: true
}
}, {
$group: {
_id: null,
usage: { $sum: '$length' }
}
}])
.then(aggregates => {
if (aggregates.length > 0) {
return aggregates[0].usage;
}
return 0;
});
await Chart.insert({
date: today,
users: {
local: {
total: localUsersCount,
diff: 0
},
remote: {
total: remoteUsersCount,
diff: 0
}
},
notes: {
local: {
total: localNotesCount,
diff: 0,
diffs: {
normal: 0,
reply: 0,
renote: 0
}
},
remote: {
total: remoteNotesCount,
diff: 0,
diffs: {
normal: 0,
reply: 0,
renote: 0
}
}
},
drive: {
local: {
totalCount: localDriveFilesCount,
totalSize: localDriveFilesSize,
diffCount: 0,
diffSize: 0
},
remote: {
totalCount: remoteDriveFilesCount,
totalSize: remoteDriveFilesSize,
diffCount: 0,
diffSize: 0
}
}
});
console.log('done');
}
main();

View file

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

View file

@ -10,6 +10,9 @@ export interface IChart {
date: Date; date: Date;
/**
*
*/
users: { users: {
local: { local: {
/** /**
@ -36,6 +39,9 @@ export interface IChart {
}; };
}; };
/**
* 稿
*/
notes: { notes: {
local: { local: {
/** /**
@ -95,4 +101,53 @@ export interface IChart {
}; };
}; };
}; };
/**
* ()
*/
drive: {
local: {
/**
*
*/
totalCount: number;
/**
*
*/
totalSize: number;
/**
*
*/
diffCount: number;
/**
*
*/
diffSize: number;
};
remote: {
/**
*
*/
totalCount: number;
/**
*
*/
totalSize: number;
/**
*
*/
diffCount: number;
/**
*
*/
diffSize: number;
};
};
} }

View file

@ -52,6 +52,11 @@ export type IDriveFile = {
filename: string; filename: string;
contentType: string; contentType: string;
metadata: IMetadata; metadata: IMetadata;
/**
*
*/
length: number;
}; };
export function validateFileName(name: string): boolean { export function validateFileName(name: string): boolean {

View file

@ -1,6 +1,7 @@
import { INote } from '../models/note'; import { INote } from '../models/note';
import Chart, { IChart } from '../models/chart'; import Chart, { IChart } from '../models/chart';
import { isLocalUser, IUser } from '../models/user'; import { isLocalUser, IUser } from '../models/user';
import { IDriveFile } from '../models/drive-file';
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
@ -63,6 +64,20 @@ async function getTodayStats(): Promise<IChart> {
renote: 0 renote: 0
} }
} }
},
drive: {
local: {
totalCount: 0,
totalSize: 0,
diffCount: 0,
diffSize: 0
},
remote: {
totalCount: 0,
totalSize: 0,
diffCount: 0,
diffSize: 0
}
} }
}; };
@ -102,6 +117,20 @@ async function getTodayStats(): Promise<IChart> {
renote: 0 renote: 0
} }
} }
},
drive: {
local: {
totalCount: mostRecentStats.drive.local.totalCount,
totalSize: mostRecentStats.drive.local.totalSize,
diffCount: 0,
diffSize: 0
},
remote: {
totalCount: mostRecentStats.drive.remote.totalCount,
totalSize: mostRecentStats.drive.remote.totalSize,
diffCount: 0,
diffSize: 0
}
} }
}; };
@ -127,14 +156,14 @@ async function update(inc: any) {
export async function updateUserStats(user: IUser, isAdditional: boolean) { export async function updateUserStats(user: IUser, isAdditional: boolean) {
const inc = {} as any; const inc = {} as any;
const val = isAdditional ? 1 : -1; const amount = isAdditional ? 1 : -1;
if (isLocalUser(user)) { if (isLocalUser(user)) {
inc['users.local.total'] = val; inc['users.local.total'] = amount;
inc['users.local.diff'] = val; inc['users.local.diff'] = amount;
} else { } else {
inc['users.remote.total'] = val; inc['users.remote.total'] = amount;
inc['users.remote.diff'] = val; inc['users.remote.diff'] = amount;
} }
await update(inc); await update(inc);
@ -143,31 +172,52 @@ export async function updateUserStats(user: IUser, isAdditional: boolean) {
export async function updateNoteStats(note: INote, isAdditional: boolean) { export async function updateNoteStats(note: INote, isAdditional: boolean) {
const inc = {} as any; const inc = {} as any;
const val = isAdditional ? 1 : -1; const amount = isAdditional ? 1 : -1;
if (isLocalUser(note._user)) { if (isLocalUser(note._user)) {
inc['notes.local.total'] = val; inc['notes.local.total'] = amount;
inc['notes.local.diff'] = val; inc['notes.local.diff'] = amount;
if (note.replyId != null) { if (note.replyId != null) {
inc['notes.local.diffs.reply'] = val; inc['notes.local.diffs.reply'] = amount;
} else if (note.renoteId != null) { } else if (note.renoteId != null) {
inc['notes.local.diffs.renote'] = val; inc['notes.local.diffs.renote'] = amount;
} else { } else {
inc['notes.local.diffs.normal'] = val; inc['notes.local.diffs.normal'] = amount;
} }
} else { } else {
inc['notes.remote.total'] = val; inc['notes.remote.total'] = amount;
inc['notes.remote.diff'] = val; inc['notes.remote.diff'] = amount;
if (note.replyId != null) { if (note.replyId != null) {
inc['notes.remote.diffs.reply'] = val; inc['notes.remote.diffs.reply'] = amount;
} else if (note.renoteId != null) { } else if (note.renoteId != null) {
inc['notes.remote.diffs.renote'] = val; inc['notes.remote.diffs.renote'] = amount;
} else { } else {
inc['notes.remote.diffs.normal'] = val; inc['notes.remote.diffs.normal'] = amount;
} }
} }
await update(inc); await update(inc);
} }
export async function updateDriveStats(user: IUser, file: IDriveFile, isAdditional: boolean) {
const inc = {} as any;
const amount = isAdditional ? 1 : -1;
const size = isAdditional ? file.length : -file.length;
if (isLocalUser(user)) {
inc['drive.local.totalCount'] = amount;
inc['drive.local.diffCount'] = amount;
inc['drive.local.totalSize'] = size;
inc['drive.local.diffSize'] = size;
} else {
inc['drive.remote.total'] = amount;
inc['drive.remote.diff'] = amount;
inc['drive.remote.totalSize'] = size;
inc['drive.remote.diffSize'] = size;
}
await update(inc);
}