Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
efae7a7bce | ||
![]() |
91f1c3a10a | ||
![]() |
8fc1e07136 | ||
![]() |
a62e2b83ff | ||
![]() |
e31a2f7e55 | ||
![]() |
1598e996b1 | ||
![]() |
4fb7ee760a | ||
![]() |
37865cb381 | ||
![]() |
ab8b882435 | ||
![]() |
1b2996947e | ||
![]() |
3bc9a40b48 | ||
![]() |
67b28f9b6e |
144
cli/migration/8.0.0.js
Normal file
144
cli/migration/8.0.0.js
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
const { default: Stats } = require('../../built/models/stats');
|
||||||
|
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 h = now.getHours();
|
||||||
|
const date = new Date(y, m, d, h);
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
await Stats.update({}, {
|
||||||
|
$set: {
|
||||||
|
span: 'day'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
multi: true
|
||||||
|
});
|
||||||
|
|
||||||
|
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 Stats.insert({
|
||||||
|
date: date,
|
||||||
|
span: 'hour',
|
||||||
|
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();
|
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "misskey",
|
"name": "misskey",
|
||||||
"author": "syuilo <i@syuilo.com>",
|
"author": "syuilo <i@syuilo.com>",
|
||||||
"version": "7.4.1",
|
"version": "8.1.0",
|
||||||
"clientVersion": "1.0.8790",
|
"clientVersion": "1.0.8811",
|
||||||
"codename": "nighthike",
|
"codename": "nighthike",
|
||||||
"main": "./built/index.js",
|
"main": "./built/index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
@@ -207,7 +207,7 @@
|
|||||||
"v-animate-css": "0.0.2",
|
"v-animate-css": "0.0.2",
|
||||||
"vue": "2.5.17",
|
"vue": "2.5.17",
|
||||||
"vue-cropperjs": "2.2.1",
|
"vue-cropperjs": "2.2.1",
|
||||||
"vue-js-modal": "1.3.17",
|
"vue-js-modal": "1.3.18",
|
||||||
"vue-json-tree-view": "2.1.4",
|
"vue-json-tree-view": "2.1.4",
|
||||||
"vue-loader": "15.4.0",
|
"vue-loader": "15.4.0",
|
||||||
"vue-router": "3.0.1",
|
"vue-router": "3.0.1",
|
||||||
@@ -218,7 +218,7 @@
|
|||||||
"vuex-persistedstate": "2.5.4",
|
"vuex-persistedstate": "2.5.4",
|
||||||
"web-push": "3.3.2",
|
"web-push": "3.3.2",
|
||||||
"webfinger.js": "2.6.6",
|
"webfinger.js": "2.6.6",
|
||||||
"webpack": "4.17.0",
|
"webpack": "4.17.1",
|
||||||
"webpack-cli": "3.1.0",
|
"webpack-cli": "3.1.0",
|
||||||
"websocket": "1.0.26",
|
"websocket": "1.0.26",
|
||||||
"ws": "6.0.0",
|
"ws": "6.0.0",
|
||||||
|
@@ -176,7 +176,7 @@ export default Vue.extend({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="stylus" scoped>
|
<style lang="stylus" scoped>
|
||||||
.twitter
|
.player
|
||||||
position relative
|
position relative
|
||||||
width 100%
|
width 100%
|
||||||
|
|
||||||
|
@@ -1,11 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`">
|
<div>
|
||||||
<polyline
|
<a @click="span = 'day'">Per day</a> | <a @click="span = 'hour'">Per hour</a>
|
||||||
:points="points"
|
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`">
|
||||||
fill="none"
|
<polyline
|
||||||
stroke-width="1"
|
:points="points"
|
||||||
stroke="#555"/>
|
fill="none"
|
||||||
</svg>
|
stroke-width="0.3"
|
||||||
|
stroke="#555"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@@ -23,20 +26,40 @@ export default Vue.extend({
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
viewBoxX: 365,
|
viewBoxX: 100,
|
||||||
viewBoxY: 70,
|
viewBoxY: 30,
|
||||||
points: null
|
points: null,
|
||||||
|
span: 'day'
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
computed: {
|
||||||
const peak = Math.max.apply(null, this.chart.map(d => this.type == 'local' ? d.drive.local.totalSize : d.drive.remote.totalSize));
|
stats(): any[] {
|
||||||
|
return (
|
||||||
|
this.span == 'day' ? this.chart.perDay :
|
||||||
|
this.span == 'hour' ? this.chart.perHour :
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
stats() {
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.render();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
render() {
|
||||||
|
const peak = Math.max.apply(null, this.stats.map(d => this.type == 'local' ? d.drive.local.totalSize : d.drive.remote.totalSize));
|
||||||
|
|
||||||
if (peak != 0) {
|
if (peak != 0) {
|
||||||
const data = this.chart.slice().reverse().map(x => ({
|
const data = this.stats.slice().reverse().map(x => ({
|
||||||
size: this.type == 'local' ? x.drive.local.totalSize : x.drive.remote.totalSize
|
size: this.type == 'local' ? x.drive.local.totalSize : x.drive.remote.totalSize
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.points = data.map((d, i) => `${i},${(1 - (d.size / peak)) * this.viewBoxY}`).join(' ');
|
this.points = data.map((d, i) => `${(this.viewBoxX / data.length) * i},${(1 - (d.size / peak)) * this.viewBoxY}`).join(' ');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -1,27 +1,30 @@
|
|||||||
<template>
|
<template>
|
||||||
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`">
|
<div>
|
||||||
<polyline
|
<a @click="span = 'day'">Per day</a> | <a @click="span = 'hour'">Per hour</a>
|
||||||
:points="pointsNote"
|
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`">
|
||||||
fill="none"
|
<polyline
|
||||||
stroke-width="1"
|
:points="pointsNote"
|
||||||
stroke="#41ddde"/>
|
fill="none"
|
||||||
<polyline
|
stroke-width="0.3"
|
||||||
:points="pointsReply"
|
stroke="#41ddde"/>
|
||||||
fill="none"
|
<polyline
|
||||||
stroke-width="1"
|
:points="pointsReply"
|
||||||
stroke="#f7796c"/>
|
fill="none"
|
||||||
<polyline
|
stroke-width="0.3"
|
||||||
:points="pointsRenote"
|
stroke="#f7796c"/>
|
||||||
fill="none"
|
<polyline
|
||||||
stroke-width="1"
|
:points="pointsRenote"
|
||||||
stroke="#a1de41"/>
|
fill="none"
|
||||||
<polyline
|
stroke-width="0.3"
|
||||||
:points="pointsTotal"
|
stroke="#a1de41"/>
|
||||||
fill="none"
|
<polyline
|
||||||
stroke-width="1"
|
:points="pointsTotal"
|
||||||
stroke="#555"
|
fill="none"
|
||||||
stroke-dasharray="2 2"/>
|
stroke-width="0.3"
|
||||||
</svg>
|
stroke="#555"
|
||||||
|
stroke-dasharray="1 1"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@@ -39,29 +42,49 @@ export default Vue.extend({
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
viewBoxX: 365,
|
viewBoxX: 100,
|
||||||
viewBoxY: 70,
|
viewBoxY: 30,
|
||||||
pointsNote: null,
|
pointsNote: null,
|
||||||
pointsReply: null,
|
pointsReply: null,
|
||||||
pointsRenote: null,
|
pointsRenote: null,
|
||||||
pointsTotal: null
|
pointsTotal: null,
|
||||||
|
span: 'day'
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
computed: {
|
||||||
const peak = Math.max.apply(null, this.chart.map(d => this.type == 'local' ? d.notes.local.diff : d.notes.remote.diff));
|
stats(): any[] {
|
||||||
|
return (
|
||||||
|
this.span == 'day' ? this.chart.perDay :
|
||||||
|
this.span == 'hour' ? this.chart.perHour :
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
stats() {
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.render();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
render() {
|
||||||
|
const peak = Math.max.apply(null, this.stats.map(d => this.type == 'local' ? d.notes.local.diff : d.notes.remote.diff));
|
||||||
|
|
||||||
if (peak != 0) {
|
if (peak != 0) {
|
||||||
const data = this.chart.slice().reverse().map(x => ({
|
const data = this.stats.slice().reverse().map(x => ({
|
||||||
normal: this.type == 'local' ? x.notes.local.diffs.normal : x.notes.remote.diffs.normal,
|
normal: this.type == 'local' ? x.notes.local.diffs.normal : x.notes.remote.diffs.normal,
|
||||||
reply: this.type == 'local' ? x.notes.local.diffs.reply : x.notes.remote.diffs.reply,
|
reply: this.type == 'local' ? x.notes.local.diffs.reply : x.notes.remote.diffs.reply,
|
||||||
renote: this.type == 'local' ? x.notes.local.diffs.renote : x.notes.remote.diffs.renote,
|
renote: this.type == 'local' ? x.notes.local.diffs.renote : x.notes.remote.diffs.renote,
|
||||||
total: this.type == 'local' ? x.notes.local.diff : x.notes.remote.diff
|
total: this.type == 'local' ? x.notes.local.diff : x.notes.remote.diff
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.pointsNote = data.map((d, i) => `${i},${(1 - (d.normal / peak)) * this.viewBoxY}`).join(' ');
|
this.pointsNote = data.map((d, i) => `${(this.viewBoxX / data.length) * i},${(1 - (d.normal / peak)) * this.viewBoxY}`).join(' ');
|
||||||
this.pointsReply = data.map((d, i) => `${i},${(1 - (d.reply / peak)) * this.viewBoxY}`).join(' ');
|
this.pointsReply = data.map((d, i) => `${(this.viewBoxX / data.length) * i},${(1 - (d.reply / peak)) * this.viewBoxY}`).join(' ');
|
||||||
this.pointsRenote = data.map((d, i) => `${i},${(1 - (d.renote / peak)) * this.viewBoxY}`).join(' ');
|
this.pointsRenote = data.map((d, i) => `${(this.viewBoxX / data.length) * i},${(1 - (d.renote / peak)) * this.viewBoxY}`).join(' ');
|
||||||
this.pointsTotal = data.map((d, i) => `${i},${(1 - (d.total / peak)) * this.viewBoxY}`).join(' ');
|
this.pointsTotal = data.map((d, i) => `${(this.viewBoxX / data.length) * i},${(1 - (d.total / peak)) * this.viewBoxY}`).join(' ');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -1,11 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`">
|
<div>
|
||||||
<polyline
|
<a @click="span = 'day'">Per day</a> | <a @click="span = 'hour'">Per hour</a>
|
||||||
:points="points"
|
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`">
|
||||||
fill="none"
|
<polyline
|
||||||
stroke-width="1"
|
:points="points"
|
||||||
stroke="#555"/>
|
fill="none"
|
||||||
</svg>
|
stroke-width="0.3"
|
||||||
|
stroke="#555"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@@ -23,20 +26,40 @@ export default Vue.extend({
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
viewBoxX: 365,
|
viewBoxX: 100,
|
||||||
viewBoxY: 70,
|
viewBoxY: 30,
|
||||||
points: null
|
points: null,
|
||||||
|
span: 'day'
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
computed: {
|
||||||
const peak = Math.max.apply(null, this.chart.map(d => this.type == 'local' ? d.users.local.diff : d.users.remote.diff));
|
stats(): any[] {
|
||||||
|
return (
|
||||||
|
this.span == 'day' ? this.chart.perDay :
|
||||||
|
this.span == 'hour' ? this.chart.perHour :
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
stats() {
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.render();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
render() {
|
||||||
|
const peak = Math.max.apply(null, this.stats.map(d => this.type == 'local' ? d.users.local.diff : d.users.remote.diff));
|
||||||
|
|
||||||
if (peak != 0) {
|
if (peak != 0) {
|
||||||
const data = this.chart.slice().reverse().map(x => ({
|
const data = this.stats.slice().reverse().map(x => ({
|
||||||
count: this.type == 'local' ? x.users.local.diff : x.users.remote.diff
|
count: this.type == 'local' ? x.users.local.diff : x.users.remote.diff
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.points = data.map((d, i) => `${i},${(1 - (d.count / peak)) * this.viewBoxY}`).join(' ');
|
this.points = data.map((d, i) => `${(this.viewBoxX / data.length) * i},${(1 - (d.count / peak)) * this.viewBoxY}`).join(' ');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -10,6 +10,8 @@ export interface IStats {
|
|||||||
|
|
||||||
date: Date;
|
date: Date;
|
||||||
|
|
||||||
|
span: 'day' | 'hour';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ユーザーに関する統計
|
* ユーザーに関する統計
|
||||||
*/
|
*/
|
||||||
|
@@ -15,7 +15,7 @@ export default async (username: string, _host: string, option?: any): Promise<IU
|
|||||||
const host = toUnicode(hostAscii);
|
const host = toUnicode(hostAscii);
|
||||||
|
|
||||||
if (config.host == host) {
|
if (config.host == host) {
|
||||||
return await User.findOne({ usernameLower });
|
return await User.findOne({ usernameLower, host: null });
|
||||||
}
|
}
|
||||||
|
|
||||||
let user = await User.findOne({ usernameLower, host }, option);
|
let user = await User.findOne({ usernameLower, host }, option);
|
||||||
|
@@ -8,94 +8,130 @@ export const meta = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default (params: any) => new Promise(async (res, rej) => {
|
export default (params: any) => new Promise(async (res, rej) => {
|
||||||
|
const daysRange = 365;
|
||||||
|
const hoursRange = 24;
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const y = now.getFullYear();
|
const y = now.getFullYear();
|
||||||
const m = now.getMonth();
|
const m = now.getMonth();
|
||||||
const d = now.getDate();
|
const d = now.getDate();
|
||||||
|
const h = now.getHours();
|
||||||
|
|
||||||
const stats = await Stats.find({
|
const [statsPerDay, statsPerHour] = await Promise.all([
|
||||||
date: {
|
Stats.find({
|
||||||
$gt: new Date(y - 1, m, d)
|
span: 'day',
|
||||||
}
|
date: {
|
||||||
}, {
|
$gt: new Date(y, m, d - daysRange)
|
||||||
sort: {
|
}
|
||||||
date: -1
|
}, {
|
||||||
},
|
sort: {
|
||||||
fields: {
|
date: -1
|
||||||
_id: 0
|
},
|
||||||
}
|
fields: {
|
||||||
});
|
_id: 0
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
Stats.find({
|
||||||
|
span: 'hour',
|
||||||
|
date: {
|
||||||
|
$gt: new Date(y, m, d, h - hoursRange)
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
sort: {
|
||||||
|
date: -1
|
||||||
|
},
|
||||||
|
fields: {
|
||||||
|
_id: 0
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
const chart: Array<Omit<IStats, '_id'>> = [];
|
const format = (src: IStats[], span: 'day' | 'hour') => {
|
||||||
|
const chart: Array<Omit<Omit<IStats, '_id'>, 'span'>> = [];
|
||||||
|
|
||||||
for (let i = 364; i >= 0; i--) {
|
const range =
|
||||||
const day = new Date(y, m, d - i);
|
span == 'day' ? daysRange :
|
||||||
|
span == 'hour' ? hoursRange :
|
||||||
|
null;
|
||||||
|
|
||||||
const stat = stats.find(s => s.date.getTime() == day.getTime());
|
for (let i = (range - 1); i >= 0; i--) {
|
||||||
|
const current =
|
||||||
|
span == 'day' ? new Date(y, m, d - i) :
|
||||||
|
span == 'hour' ? new Date(y, m, d, h - i) :
|
||||||
|
null;
|
||||||
|
|
||||||
if (stat) {
|
const stat = src.find(s => s.date.getTime() == current.getTime());
|
||||||
chart.unshift(stat);
|
|
||||||
} else { // 隙間埋め
|
if (stat) {
|
||||||
const mostRecent = stats.find(s => s.date.getTime() < day.getTime());
|
chart.unshift(stat);
|
||||||
if (mostRecent) {
|
} else { // 隙間埋め
|
||||||
chart.unshift(Object.assign({}, mostRecent, {
|
const mostRecent = src.find(s => s.date.getTime() < current.getTime());
|
||||||
date: day
|
if (mostRecent) {
|
||||||
}));
|
chart.unshift(Object.assign({}, mostRecent, {
|
||||||
} else {
|
date: current
|
||||||
chart.unshift({
|
}));
|
||||||
date: day,
|
} else {
|
||||||
users: {
|
chart.unshift({
|
||||||
local: {
|
date: current,
|
||||||
total: 0,
|
users: {
|
||||||
diff: 0
|
local: {
|
||||||
},
|
total: 0,
|
||||||
remote: {
|
diff: 0
|
||||||
total: 0,
|
},
|
||||||
diff: 0
|
remote: {
|
||||||
}
|
total: 0,
|
||||||
},
|
diff: 0
|
||||||
notes: {
|
|
||||||
local: {
|
|
||||||
total: 0,
|
|
||||||
diff: 0,
|
|
||||||
diffs: {
|
|
||||||
normal: 0,
|
|
||||||
reply: 0,
|
|
||||||
renote: 0
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
remote: {
|
notes: {
|
||||||
total: 0,
|
local: {
|
||||||
diff: 0,
|
total: 0,
|
||||||
diffs: {
|
diff: 0,
|
||||||
normal: 0,
|
diffs: {
|
||||||
reply: 0,
|
normal: 0,
|
||||||
renote: 0
|
reply: 0,
|
||||||
|
renote: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
remote: {
|
||||||
|
total: 0,
|
||||||
|
diff: 0,
|
||||||
|
diffs: {
|
||||||
|
normal: 0,
|
||||||
|
reply: 0,
|
||||||
|
renote: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
drive: {
|
||||||
|
local: {
|
||||||
|
totalCount: 0,
|
||||||
|
totalSize: 0,
|
||||||
|
diffCount: 0,
|
||||||
|
diffSize: 0
|
||||||
|
},
|
||||||
|
remote: {
|
||||||
|
totalCount: 0,
|
||||||
|
totalSize: 0,
|
||||||
|
diffCount: 0,
|
||||||
|
diffSize: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
drive: {
|
}
|
||||||
local: {
|
|
||||||
totalCount: 0,
|
|
||||||
totalSize: 0,
|
|
||||||
diffCount: 0,
|
|
||||||
diffSize: 0
|
|
||||||
},
|
|
||||||
remote: {
|
|
||||||
totalCount: 0,
|
|
||||||
totalSize: 0,
|
|
||||||
diffCount: 0,
|
|
||||||
diffSize: 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
chart.forEach(x => {
|
chart.forEach(x => {
|
||||||
delete x.date;
|
delete x.date;
|
||||||
|
delete (x as any).span;
|
||||||
|
});
|
||||||
|
|
||||||
|
return chart;
|
||||||
|
};
|
||||||
|
|
||||||
|
res({
|
||||||
|
perDay: format(statsPerDay, 'day'),
|
||||||
|
perHour: format(statsPerHour, 'hour')
|
||||||
});
|
});
|
||||||
|
|
||||||
res(chart);
|
|
||||||
});
|
});
|
||||||
|
@@ -27,7 +27,11 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
|||||||
return rej('followee not found');
|
return rej('followee not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
await cancelFollowRequest(followee, user);
|
try {
|
||||||
|
await cancelFollowRequest(followee, user);
|
||||||
|
} catch (e) {
|
||||||
|
return rej(e);
|
||||||
|
}
|
||||||
|
|
||||||
// Send response
|
// Send response
|
||||||
res(await pack(followee._id, user));
|
res(await pack(followee._id, user));
|
||||||
|
@@ -12,6 +12,15 @@ export default async function(followee: IUser, follower: IUser) {
|
|||||||
deliver(follower as ILocalUser, content, followee.inbox);
|
deliver(follower as ILocalUser, content, followee.inbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const request = await FollowRequest.findOne({
|
||||||
|
followeeId: followee._id,
|
||||||
|
followerId: follower._id
|
||||||
|
});
|
||||||
|
|
||||||
|
if (request == null) {
|
||||||
|
throw 'request not found';
|
||||||
|
}
|
||||||
|
|
||||||
await FollowRequest.remove({
|
await FollowRequest.remove({
|
||||||
followeeId: followee._id,
|
followeeId: followee._id,
|
||||||
followerId: follower._id
|
followerId: follower._id
|
||||||
|
@@ -5,89 +5,46 @@ 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>>;
|
||||||
|
|
||||||
async function getTodayStats(): Promise<IStats> {
|
async function getCurrentStats(span: 'day' | 'hour'): Promise<IStats> {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const y = now.getFullYear();
|
const y = now.getFullYear();
|
||||||
const m = now.getMonth();
|
const m = now.getMonth();
|
||||||
const d = now.getDate();
|
const d = now.getDate();
|
||||||
const today = new Date(y, m, d);
|
const h = now.getHours();
|
||||||
|
|
||||||
// 今日の統計
|
const current =
|
||||||
const todayStats = await Stats.findOne({
|
span == 'day' ? new Date(y, m, d) :
|
||||||
date: today
|
span == 'hour' ? new Date(y, m, d, h) :
|
||||||
|
null;
|
||||||
|
|
||||||
|
// 現在(今日または今のHour)の統計
|
||||||
|
const currentStats = await Stats.findOne({
|
||||||
|
span: span,
|
||||||
|
date: current
|
||||||
});
|
});
|
||||||
|
|
||||||
// 日付が変わってから、初めてのチャート更新なら
|
if (currentStats) {
|
||||||
if (todayStats == null) {
|
return currentStats;
|
||||||
|
} else {
|
||||||
|
// 集計期間が変わってから、初めてのチャート更新なら
|
||||||
// 最も最近の統計を持ってくる
|
// 最も最近の統計を持ってくる
|
||||||
|
// * 例えば集計期間が「日」である場合で考えると、
|
||||||
// * 昨日何もチャートを更新するような出来事がなかった場合は、
|
// * 昨日何もチャートを更新するような出来事がなかった場合は、
|
||||||
// 統計がそもそも作られずドキュメントが存在しないということがあり得るため、
|
// * 統計がそもそも作られずドキュメントが存在しないということがあり得るため、
|
||||||
// 「昨日の」と決め打ちせずに「もっとも最近の」とします
|
// * 「昨日の」と決め打ちせずに「もっとも最近の」とします
|
||||||
const mostRecentStats = await Stats.findOne({}, {
|
const mostRecentStats = await Stats.findOne({
|
||||||
|
span: span
|
||||||
|
}, {
|
||||||
sort: {
|
sort: {
|
||||||
date: -1
|
date: -1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 統計が存在しなかったら
|
if (mostRecentStats) {
|
||||||
// * Misskeyインスタンスを建てて初めてのチャート更新時など
|
// 現在の統計を初期挿入
|
||||||
if (mostRecentStats == null) {
|
|
||||||
// 空の統計を作成
|
|
||||||
const data: Omit<IStats, '_id'> = {
|
const data: Omit<IStats, '_id'> = {
|
||||||
date: today,
|
span: span,
|
||||||
users: {
|
date: current,
|
||||||
local: {
|
|
||||||
total: 0,
|
|
||||||
diff: 0
|
|
||||||
},
|
|
||||||
remote: {
|
|
||||||
total: 0,
|
|
||||||
diff: 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
notes: {
|
|
||||||
local: {
|
|
||||||
total: 0,
|
|
||||||
diff: 0,
|
|
||||||
diffs: {
|
|
||||||
normal: 0,
|
|
||||||
reply: 0,
|
|
||||||
renote: 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
remote: {
|
|
||||||
total: 0,
|
|
||||||
diff: 0,
|
|
||||||
diffs: {
|
|
||||||
normal: 0,
|
|
||||||
reply: 0,
|
|
||||||
renote: 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
drive: {
|
|
||||||
local: {
|
|
||||||
totalCount: 0,
|
|
||||||
totalSize: 0,
|
|
||||||
diffCount: 0,
|
|
||||||
diffSize: 0
|
|
||||||
},
|
|
||||||
remote: {
|
|
||||||
totalCount: 0,
|
|
||||||
totalSize: 0,
|
|
||||||
diffCount: 0,
|
|
||||||
diffSize: 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const stats = await Stats.insert(data);
|
|
||||||
|
|
||||||
return stats;
|
|
||||||
} else {
|
|
||||||
// 今日の統計を初期挿入
|
|
||||||
const data: Omit<IStats, '_id'> = {
|
|
||||||
date: today,
|
|
||||||
users: {
|
users: {
|
||||||
local: {
|
local: {
|
||||||
total: mostRecentStats.users.local.total,
|
total: mostRecentStats.users.local.total,
|
||||||
@@ -136,20 +93,83 @@ async function getTodayStats(): Promise<IStats> {
|
|||||||
|
|
||||||
const stats = await Stats.insert(data);
|
const stats = await Stats.insert(data);
|
||||||
|
|
||||||
|
return stats;
|
||||||
|
} else {
|
||||||
|
// 統計が存在しなかったら
|
||||||
|
// * Misskeyインスタンスを建てて初めてのチャート更新時など
|
||||||
|
|
||||||
|
// 空の統計を作成
|
||||||
|
const emptyStat: Omit<IStats, '_id'> = {
|
||||||
|
span: span,
|
||||||
|
date: current,
|
||||||
|
users: {
|
||||||
|
local: {
|
||||||
|
total: 0,
|
||||||
|
diff: 0
|
||||||
|
},
|
||||||
|
remote: {
|
||||||
|
total: 0,
|
||||||
|
diff: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
notes: {
|
||||||
|
local: {
|
||||||
|
total: 0,
|
||||||
|
diff: 0,
|
||||||
|
diffs: {
|
||||||
|
normal: 0,
|
||||||
|
reply: 0,
|
||||||
|
renote: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
remote: {
|
||||||
|
total: 0,
|
||||||
|
diff: 0,
|
||||||
|
diffs: {
|
||||||
|
normal: 0,
|
||||||
|
reply: 0,
|
||||||
|
renote: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
drive: {
|
||||||
|
local: {
|
||||||
|
totalCount: 0,
|
||||||
|
totalSize: 0,
|
||||||
|
diffCount: 0,
|
||||||
|
diffSize: 0
|
||||||
|
},
|
||||||
|
remote: {
|
||||||
|
totalCount: 0,
|
||||||
|
totalSize: 0,
|
||||||
|
diffCount: 0,
|
||||||
|
diffSize: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const stats = await Stats.insert(emptyStat);
|
||||||
|
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return todayStats;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function update(inc: any) {
|
function update(inc: any) {
|
||||||
const stats = await getTodayStats();
|
getCurrentStats('day').then(stats => {
|
||||||
|
Stats.findOneAndUpdate({
|
||||||
|
_id: stats._id
|
||||||
|
}, {
|
||||||
|
$inc: inc
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
await Stats.findOneAndUpdate({
|
getCurrentStats('hour').then(stats => {
|
||||||
_id: stats._id
|
Stats.findOneAndUpdate({
|
||||||
}, {
|
_id: stats._id
|
||||||
$inc: inc
|
}, {
|
||||||
|
$inc: inc
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user