Improve instance stats
This commit is contained in:
parent
0bf602bae6
commit
336912e442
6 changed files with 78 additions and 6 deletions
|
|
@ -10,6 +10,8 @@ import renderReject from '../../remote/activitypub/renderer/reject';
|
|||
import { deliver } from '../../queue';
|
||||
import createFollowRequest from './requests/create';
|
||||
import perUserFollowingChart from '../../chart/per-user-following';
|
||||
import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc';
|
||||
import Instance from '../../models/instance';
|
||||
|
||||
export default async function(follower: IUser, followee: IUser, requestId?: string) {
|
||||
// check blocking
|
||||
|
|
@ -97,6 +99,32 @@ export default async function(follower: IUser, followee: IUser, requestId?: stri
|
|||
});
|
||||
//#endregion
|
||||
|
||||
//#region Update instance stats
|
||||
if (isRemoteUser(follower) && isLocalUser(followee)) {
|
||||
registerOrFetchInstanceDoc(follower.host).then(i => {
|
||||
Instance.update({ _id: i._id }, {
|
||||
$inc: {
|
||||
followingCount: 1
|
||||
}
|
||||
});
|
||||
|
||||
// TODO
|
||||
//perInstanceChart.newFollowing();
|
||||
});
|
||||
} else if (isLocalUser(follower) && isRemoteUser(followee)) {
|
||||
registerOrFetchInstanceDoc(followee.host).then(i => {
|
||||
Instance.update({ _id: i._id }, {
|
||||
$inc: {
|
||||
followersCount: 1
|
||||
}
|
||||
});
|
||||
|
||||
// TODO
|
||||
//perInstanceChart.newFollower();
|
||||
});
|
||||
}
|
||||
//#endregion
|
||||
|
||||
perUserFollowingChart.update(follower, followee, true);
|
||||
|
||||
// Publish follow event
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import activeUsersChart from '../../chart/active-users';
|
|||
|
||||
import { erase, concat } from '../../prelude/array';
|
||||
import insertNoteUnread from './unread';
|
||||
import registerInstance from '../register-instance';
|
||||
import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc';
|
||||
import Instance from '../../models/instance';
|
||||
import extractMentions from '../../misc/extract-mentions';
|
||||
import extractEmojis from '../../misc/extract-emojis';
|
||||
|
|
@ -222,7 +222,7 @@ export default async (user: IUser, data: Option, silent = false) => new Promise<
|
|||
|
||||
// Register host
|
||||
if (isRemoteUser(user)) {
|
||||
registerInstance(user.host).then(i => {
|
||||
registerOrFetchInstanceDoc(user.host).then(i => {
|
||||
Instance.update({ _id: i._id }, {
|
||||
$inc: {
|
||||
notesCount: 1
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import Instance, { IInstance } from '../models/instance';
|
||||
import federationChart from '../chart/federation';
|
||||
|
||||
export default async function(host: string): Promise<IInstance> {
|
||||
export async function registerOrFetchInstanceDoc(host: string): Promise<IInstance> {
|
||||
if (host == null) return null;
|
||||
|
||||
const index = await Instance.findOne({ host });
|
||||
Loading…
Add table
Add a link
Reference in a new issue