updated gallery
This commit is contained in:
@@ -276,7 +276,7 @@ class ArtworkService
|
||||
$q->where('af.type', $type);
|
||||
})
|
||||
->with([
|
||||
'user:id,name',
|
||||
'user:id,name,username',
|
||||
'categories' => function ($q) {
|
||||
$q->select('categories.id', 'categories.content_type_id', 'categories.parent_id', 'categories.name', 'categories.slug', 'categories.sort_order');
|
||||
},
|
||||
|
||||
@@ -254,8 +254,25 @@ final class TagService
|
||||
|
||||
public function updateUsageCount(Tag $tag): void
|
||||
{
|
||||
$this->syncUsageCount($tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculate and persist the real usage_count from artwork_tag.
|
||||
*
|
||||
* @return array{before:int, after:int, changed:bool}
|
||||
*/
|
||||
public function syncUsageCount(Tag $tag): array
|
||||
{
|
||||
$before = (int) $tag->usage_count;
|
||||
$count = (int) DB::table('artwork_tag')->where('tag_id', $tag->id)->count();
|
||||
$tag->forceFill(['usage_count' => $count])->save();
|
||||
|
||||
return [
|
||||
'before' => $before,
|
||||
'after' => $count,
|
||||
'changed' => $before !== $count,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user