Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icon Suggestion #1001

Merged
merged 10 commits into from
Jan 28, 2025
25 changes: 25 additions & 0 deletions app/Facades/BookmarkCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Facades;

use Illuminate\Support\Facades\Facade;

/**
* Class BookmarkCache
* @package App\Facades
*
* @see \App\Services\Caches\BookmarkCacheService
* @mixin \App\Services\Caches\BookmarkCacheService
*/
class BookmarkCache extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'bookmarkcache';
}
}
25 changes: 25 additions & 0 deletions app/Facades/EntityAssetCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Facades;

use Illuminate\Support\Facades\Facade;

/**
* Class EntityAssetCache
* @package App\Facades
*
* @see \App\Services\Caches\EntityAssetCacheService
* @mixin \App\Services\Caches\EntityAssetCacheService
*/
class EntityAssetCache extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'entityassetcache';
}
}
3 changes: 0 additions & 3 deletions app/Http/Controllers/Campaign/MemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

namespace App\Http\Controllers\Campaign;

use App\Exceptions\TranslatableException;
use App\Facades\Identity;
use App\Http\Controllers\Controller;
use App\Http\Requests\UpdateUserRoles;
use App\Models\Campaign;
use App\Models\CampaignUser;
use App\Models\Entity;
use App\Services\Campaign\MemberService;

class MemberController extends Controller
{
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/Campaign/Members/RoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class RoleController extends Controller
*/
public function __construct(
protected MemberService $memberService
)
{
) {
$this->middleware('auth');
}

Expand Down
7 changes: 7 additions & 0 deletions app/Models/Bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace App\Models;

use App\Facades\BookmarkCache;
use App\Facades\CampaignLocalization;
use App\Facades\Dashboard;
use App\Models\Concerns\HasCampaign;
use App\Models\Concerns\HasFilters;
use App\Models\Concerns\HasSuggestions;
use App\Models\Concerns\LastSync;
use App\Models\Concerns\Orderable;
use App\Models\Concerns\Privatable;
Expand Down Expand Up @@ -54,6 +56,7 @@ class Bookmark extends Model
use HasCampaign;
use HasFactory;
use HasFilters;
use HasSuggestions;
use LastSync;
use Orderable;
use Privatable;
Expand Down Expand Up @@ -121,6 +124,10 @@ class Bookmark extends Model
'target',
];

protected array $suggestions = [
BookmarkCache::class => 'clearSuggestion',
spitfire305 marked this conversation as resolved.
Show resolved Hide resolved
];

/**
* Set to false if this entity type doesn't have relations
*/
Expand Down
7 changes: 7 additions & 0 deletions app/Models/EntityAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace App\Models;

use App\Facades\EntityAssetCache;
use App\Facades\Img;
use App\Models\Concerns\Blameable;
use App\Models\Concerns\HasSuggestions;
use App\Models\Concerns\HasVisibility;
use App\Models\Concerns\Sanitizable;
use App\Models\Scopes\EntityAssetScopes;
Expand Down Expand Up @@ -37,6 +39,7 @@ class EntityAsset extends Model
use Blameable;
use EntityAssetScopes;
use HasFactory;
use HasSuggestions;
use HasVisibility;
use Pinnable;
use Sanitizable;
Expand Down Expand Up @@ -66,6 +69,10 @@ class EntityAsset extends Model
'metadata.url',
];

protected array $suggestions = [
EntityAssetCache::class => 'clearSuggestion',
];

public function entity(): BelongsTo
{
return $this->belongsTo(Entity::class);
Expand Down
24 changes: 12 additions & 12 deletions app/Models/Journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ class Journal extends MiscModel
public function scopePreparedWith(Builder $query): Builder
{
return parent::scopePreparedWith($query->with([
// 'entity.calendarDate',
// 'entity.calendarDate.calendar',
// 'entity.calendarDate.calendar.entity',
// 'location' => function ($sub) {
// $sub->select('id', 'name');
// },
// 'author' => function ($sub) {
// $sub->select('id', 'name');
// },
// 'location.entity' => function ($sub) {
// $sub->select('id', 'name', 'entity_id', 'type_id');
// },
// 'entity.calendarDate',
// 'entity.calendarDate.calendar',
// 'entity.calendarDate.calendar.entity',
// 'location' => function ($sub) {
// $sub->select('id', 'name');
// },
// 'author' => function ($sub) {
// $sub->select('id', 'name');
// },
// 'location.entity' => function ($sub) {
// $sub->select('id', 'name', 'entity_id', 'type_id');
// },
]));
}

Expand Down
18 changes: 18 additions & 0 deletions app/Providers/CacheServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

use App\Facades\CampaignLocalization;
use App\Services\Caches\AdCacheService;
use App\Services\Caches\BookmarkCacheService;
use App\Services\Caches\CampaignCacheService;
use App\Services\Caches\CharacterCacheService;
use App\Services\Caches\EntityAssetCacheService;
use App\Services\Caches\MarketplaceCacheService;
use App\Services\Caches\QuestCacheService;
use App\Services\Caches\MapMarkerCacheService;
Expand Down Expand Up @@ -75,6 +77,20 @@ public function register()
}
return $service;
});
$this->app->singleton(EntityAssetCacheService::class, function () {
$service = new EntityAssetCacheService();
if (CampaignLocalization::hasCampaign()) {
$service->campaign(CampaignLocalization::getCampaign());
}
return $service;
});
$this->app->singleton(BookmarkCacheService::class, function () {
$service = new BookmarkCacheService();
if (CampaignLocalization::hasCampaign()) {
$service->campaign(CampaignLocalization::getCampaign());
}
return $service;
});
$this->app->singleton(TimelineElementCacheService::class, function () {
$service = new TimelineElementCacheService();
if (CampaignLocalization::hasCampaign()) {
Expand All @@ -96,6 +112,8 @@ public function register()
$this->app->alias(FrontCacheService::class, 'frontcache');
$this->app->alias(AdCacheService::class, 'adcache');
$this->app->alias(MapMarkerCacheService::class, 'mapmarkercache');
$this->app->alias(EntityAssetCacheService::class, 'entityassetcache');
$this->app->alias(BookmarkCacheService::class, 'bookmarkcache');
$this->app->alias(TimelineElementCacheService::class, 'timelineelementcache');
$this->app->alias(MarketplaceCacheService::class, 'marketplacecache');
}
Expand Down
57 changes: 57 additions & 0 deletions app/Services/Caches/BookmarkCacheService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Services\Caches;

use App\Models\Bookmark;
use App\Traits\CampaignAware;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class BookmarkCacheService extends BaseCache
{
use CampaignAware;

/**
*/
public function iconSuggestion(): array
{
$key = $this->iconSuggestionKey();
if (Cache::has($key)) {
return Cache::get($key);
}

$data = Bookmark::where('campaign_id', $this->campaign->id)
->whereNotNull('icon')
->select(DB::raw('icon, MAX(created_at) as cmat'))
->groupBy('icon')
->orderBy('cmat', 'DESC')
->take(10)
->pluck('icon')
->all();

$data = array_slice($data, 0, 10);

Cache::put($key, $data, 24 * 3600);
return $data;
}

/**
* @return $this
*/
public function clearSuggestion(): self
{
$this->forget(
$this->iconSuggestionKey()
);
return $this;
}


/**
* Type suggestion cache key
*/
protected function iconSuggestionKey(): string
{
return 'campaign_' . $this->campaign->id . '_bookmark_suggestions';
}
}
77 changes: 77 additions & 0 deletions app/Services/Caches/EntityAssetCacheService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace App\Services\Caches;

use App\Models\EntityAsset;
use App\Traits\CampaignAware;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class EntityAssetCacheService extends BaseCache
{
use CampaignAware;

/**
*/
public function iconSuggestion(): array
{
$key = $this->iconSuggestionKey();
if (Cache::has($key)) {
return Cache::get($key);
}

$default = [
spitfire305 marked this conversation as resolved.
Show resolved Hide resolved
'fa-brands fa-d-and-d-beyond',
'ra ra-aura',
];

$data = [];

$settings = EntityAsset::leftJoin('entities as e', 'e.id', 'entity_assets.entity_id')
->where('e.campaign_id', $this->campaign->id)
->select(DB::raw('metadata, MAX(entity_assets.created_at) as cmat'))
->groupBy('metadata')
->whereNotNull('metadata->icon')
->where('entity_assets.type_id', EntityAsset::TYPE_LINK)
->orderBy('cmat', 'DESC')
->take(10)
->pluck('metadata')
->all();


foreach ($settings as $setting) {
$data[] = $setting['icon'];
}

foreach ($default as $value) {
if (!in_array($value, $data)) {
spitfire305 marked this conversation as resolved.
Show resolved Hide resolved
$data[] = $value;
}
}

$data = array_slice($data, 0, 10);

Cache::put($key, $data, 24 * 3600);
return $data;
}

/**
* @return $this
*/
public function clearSuggestion(): self
{
$this->forget(
$this->iconSuggestionKey()
);
return $this;
}


/**
* Type suggestion cache key
*/
protected function iconSuggestionKey(): string
{
return 'campaign_' . $this->campaign->id . '_entity_asset_suggestions';
}
}
4 changes: 4 additions & 0 deletions app/Services/Campaign/Import/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace App\Services\Campaign\Import;

use App\Enums\CampaignImportStatus;
use App\Facades\BookmarkCache;
use App\Facades\CampaignCache;
use App\Facades\CharacterCache;
use App\Facades\EntityAssetCache;
use App\Facades\EntityCache;
use App\Facades\MapMarkerCache;
use App\Facades\QuestCache;
Expand Down Expand Up @@ -284,6 +286,8 @@ protected function moduleSettings(): self
TimelineElementCache::campaign($this->campaign);
QuestCache::campaign($this->campaign);
MapMarkerCache::campaign($this->campaign);
EntityAssetCache::campaign($this->campaign);
BookmarkCache::campaign($this->campaign);

return $this;
}
Expand Down
5 changes: 2 additions & 3 deletions app/View/Components/Posts/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ class Tags extends Component
public function __construct(
public Post $post,
public Campaign $campaign
)
{
//
) {

}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/View/Components/PostsTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PostsTags extends Component
*/
public function __construct()
{
//

}

/**
Expand Down
Loading