Improve instance stats

This commit is contained in:
syuilo 2019-02-07 15:00:44 +09:00
parent 0bf602bae6
commit 336912e442
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
6 changed files with 78 additions and 6 deletions

View file

@ -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