Update Nodeinfo util, use last_active_at for monthly active user count

This commit is contained in:
Daniel Supernault 2021-02-28 23:25:37 -07:00
parent b2501bfcc3
commit d200c12cf2
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -12,24 +12,31 @@ class Nodeinfo {
{ {
$res = Cache::remember('api:nodeinfo', now()->addMinutes(15), function () { $res = Cache::remember('api:nodeinfo', now()->addMinutes(15), function () {
$activeHalfYear = Cache::remember('api:nodeinfo:ahy', now()->addHours(12), function() { $activeHalfYear = Cache::remember('api:nodeinfo:ahy', now()->addHours(12), function() {
// todo: replace with last_active_at after July 9, 2021 (96afc3e781)
$count = collect([]); $count = collect([]);
$likes = Like::select('profile_id')->with('actor')->where('created_at', '>', now()->subMonths(6)->toDateTimeString())->groupBy('profile_id')->get()->filter(function($like) {return $like->actor && $like->actor->domain == null;})->pluck('profile_id')->toArray(); $likes = Like::select('profile_id')->with('actor')->where('created_at', '>', now()->subMonths(6)->toDateTimeString())->groupBy('profile_id')->get()->filter(function($like) {return $like->actor && $like->actor->domain == null;})->pluck('profile_id')->toArray();
$count = $count->merge($likes); $count = $count->merge($likes);
$statuses = Status::select('profile_id')->whereLocal(true)->where('created_at', '>', now()->subMonths(6)->toDateTimeString())->groupBy('profile_id')->pluck('profile_id')->toArray(); $statuses = Status::select('profile_id')->whereLocal(true)->where('created_at', '>', now()->subMonths(6)->toDateTimeString())->groupBy('profile_id')->pluck('profile_id')->toArray();
$count = $count->merge($statuses); $count = $count->merge($statuses);
$profiles = Profile::select('id')->whereNull('domain')->where('created_at', '>', now()->subMonths(6)->toDateTimeString())->groupBy('id')->pluck('id')->toArray(); $profiles = User::select('profile_id', 'last_active_at')
->whereNotNull('last_active_at')
->where('last_active_at', '>', now()->subMonths(6))
->pluck('profile_id')
->toArray();
$newProfiles = User::select('profile_id', 'last_active_at', 'created_at')
->whereNull('last_active_at')
->where('created_at', '>', now()->subMonths(6))
->pluck('profile_id')
->toArray();
$count = $count->merge($newProfiles);
$count = $count->merge($profiles); $count = $count->merge($profiles);
return $count->unique()->count(); return $count->unique()->count();
}); });
$activeMonth = Cache::remember('api:nodeinfo:am', now()->addHours(12), function() { $activeMonth = Cache::remember('api:nodeinfo:am', now()->addHours(2), function() {
$count = collect([]); return User::select('last_active_at')
$likes = Like::select('profile_id')->where('created_at', '>', now()->subMonths(1)->toDateTimeString())->groupBy('profile_id')->get()->filter(function($like) {return $like->actor && $like->actor->domain == null;})->pluck('profile_id')->toArray(); ->where('last_active_at', '>', now()->subMonths(1))
$count = $count->merge($likes); ->orWhere('created_at', '>', now()->subMonths(1))
$statuses = Status::select('profile_id')->whereLocal(true)->where('created_at', '>', now()->subMonths(1)->toDateTimeString())->groupBy('profile_id')->pluck('profile_id')->toArray(); ->count();
$count = $count->merge($statuses);
$profiles = Profile::select('id')->whereNull('domain')->where('created_at', '>', now()->subMonths(1)->toDateTimeString())->groupBy('id')->pluck('id')->toArray();
$count = $count->merge($profiles);
return $count->unique()->count();
}); });
return [ return [
'metadata' => [ 'metadata' => [