Skip to content

Commit

Permalink
Update Profile, fix status count
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Dec 27, 2020
1 parent b74e14c commit 6dcd472
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 15 deletions.
56 changes: 56 additions & 0 deletions app/Console/Commands/FixStatusCount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Profile;

class FixStatusCount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'fix:statuscount';

/**
* The console command description.
*
* @var string
*/
protected $description = 'fix profile status count';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
Profile::whereNull('domain')
->chunk(50, function($profiles) {
foreach($profiles as $profile) {
$profile->status_count = $profile->statuses()
->getQuery()
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->count();
$profile->save();
}
});

return 0;
}
}
1 change: 1 addition & 0 deletions app/Http/Controllers/StatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public function delete(Request $request)
}

Cache::forget('_api:statuses:recent_9:' . $status->profile_id);
Cache::forget('profile:status_count:' . $status->profile_id);
if ($status->profile_id == $user->profile->id || $user->is_admin == true) {
Cache::forget('profile:status_count:'.$status->profile_id);
StatusDelete::dispatch($status);
Expand Down
11 changes: 11 additions & 0 deletions app/Jobs/StatusPipeline/StatusDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ public function __construct(Status $status)
public function handle()
{
$status = $this->status;
$profile = $this->status->profile;

$count = $profile->statuses()
->getQuery()
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->count();

$profile->status_count = ($count - 1);
$profile->save();

if(config('federation.activitypub.enabled') == true) {
$this->fanoutDelete($status);
Expand Down
11 changes: 11 additions & 0 deletions app/Jobs/StatusPipeline/StatusEntityLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ public function __construct(Status $status)
public function handle()
{
$profile = $this->status->profile;

$count = $profile->statuses()
->getQuery()
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->count();

$profile->status_count = $count;
$profile->save();

if($profile->no_autolink == false) {
$this->parseEntities();
}
Expand Down
16 changes: 1 addition & 15 deletions app/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,7 @@ public function followerCount($short = false)

public function statusCount()
{
return Cache::remember('profile:status_count:'.$this->id, now()->addMonths(1), function() {
$count = $this->status_count;
if($count) {
return $count;
}
$count = $this->statuses()
->getQuery()
->whereHas('media')
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->count();
$this->status_count = $count;
$this->save();
return $count;
});
return $this->status_count;
}

public function following()
Expand Down

0 comments on commit 6dcd472

Please sign in to comment.