mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update nodeinfo
This commit is contained in:
parent
b76ad7cfe0
commit
36df0d8373
3 changed files with 89 additions and 84 deletions
|
@ -34,6 +34,7 @@ use App\Transformer\Api\Mastodon\v1\{
|
|||
use App\Transformer\Api\{
|
||||
RelationshipTransformer,
|
||||
};
|
||||
use App\Util\Site\Nodeinfo;
|
||||
|
||||
class ApiV2Controller extends Controller
|
||||
{
|
||||
|
@ -77,12 +78,7 @@ class ApiV2Controller extends Controller
|
|||
'description' => config_cache('app.short_description'),
|
||||
'usage' => [
|
||||
'users' => [
|
||||
'active_month' => (int) Cache::remember('api:nodeinfo:am', 172800, function() {
|
||||
return User::select('last_active_at', 'created_at')
|
||||
->where('last_active_at', '>', now()->subMonths(1))
|
||||
->orWhere('created_at', '>', now()->subMonths(1))
|
||||
->count();
|
||||
})
|
||||
'active_month' => (int) Nodeinfo::activeUsersMonthly()
|
||||
]
|
||||
],
|
||||
'thumbnail' => [
|
||||
|
|
|
@ -9,17 +9,13 @@ use Illuminate\Support\Facades\Redis;
|
|||
use App\Status;
|
||||
use App\User;
|
||||
use App\Services\AccountService;
|
||||
use App\Util\Site\Nodeinfo;
|
||||
|
||||
class LandingService
|
||||
{
|
||||
public static function get($json = true)
|
||||
{
|
||||
$activeMonth = Cache::remember('api:nodeinfo:am', 172800, function() {
|
||||
return User::select('last_active_at')
|
||||
->where('last_active_at', '>', now()->subMonths(1))
|
||||
->orWhere('created_at', '>', now()->subMonths(1))
|
||||
->count();
|
||||
});
|
||||
$activeMonth = Nodeinfo::activeUsersMonthly();
|
||||
|
||||
$totalUsers = Cache::remember('api:nodeinfo:users', 43200, function() {
|
||||
return User::count();
|
||||
|
|
|
@ -2,28 +2,20 @@
|
|||
|
||||
namespace App\Util\Site;
|
||||
|
||||
use Cache;
|
||||
use App\{Like, Profile, Status, User};
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Like;
|
||||
use App\Profile;
|
||||
use App\Status;
|
||||
use App\User;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Nodeinfo {
|
||||
|
||||
class Nodeinfo
|
||||
{
|
||||
public static function get()
|
||||
{
|
||||
$res = Cache::remember('api:nodeinfo', 300, function () {
|
||||
$activeHalfYear = Cache::remember('api:nodeinfo:ahy', 172800, function() {
|
||||
return User::select('last_active_at')
|
||||
->where('last_active_at', '>', now()->subMonths(6))
|
||||
->orWhere('created_at', '>', now()->subMonths(6))
|
||||
->count();
|
||||
});
|
||||
|
||||
$activeMonth = Cache::remember('api:nodeinfo:am', 172800, function() {
|
||||
return User::select('last_active_at')
|
||||
->where('last_active_at', '>', now()->subMonths(1))
|
||||
->orWhere('created_at', '>', now()->subMonths(1))
|
||||
->count();
|
||||
});
|
||||
$res = Cache::remember('api:nodeinfo', 900, function () {
|
||||
$activeHalfYear = self::activeUsersHalfYear();
|
||||
$activeMonth = self::activeUsersMonthly();
|
||||
|
||||
$users = Cache::remember('api:nodeinfo:users', 43200, function() {
|
||||
return User::count();
|
||||
|
@ -83,4 +75,25 @@ class Nodeinfo {
|
|||
];
|
||||
}
|
||||
|
||||
public static function activeUsersMonthly()
|
||||
{
|
||||
return Cache::remember('api:nodeinfo:active-users-monthly', 43200, function() {
|
||||
return User::withTrashed()
|
||||
->select('last_active_at, updated_at')
|
||||
->where('updated_at', '>', now()->subWeeks(5))
|
||||
->orWhere('last_active_at', '>', now()->subWeeks(5))
|
||||
->count();
|
||||
});
|
||||
}
|
||||
|
||||
public static function activeUsersHalfYear()
|
||||
{
|
||||
return Cache::remember('api:nodeinfo:active-users-half-year', 43200, function() {
|
||||
return User::withTrashed()
|
||||
->select('last_active_at, updated_at')
|
||||
->where('last_active_at', '>', now()->subMonths(6))
|
||||
->orWhere('updated_at', '>', now()->subMonths(6))
|
||||
->count();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue