add clear cache to edu programs, fix relationships bugs
This commit is contained in:
@@ -7,8 +7,8 @@ use Filament\Support\Contracts\HasColor;
|
||||
|
||||
enum BudgetEducation: int implements HasLabel, HasColor
|
||||
{
|
||||
case budget_quantity_position = 1; // Очная форма обучения
|
||||
case non_budget_quantity_position = 2; // Заочная форма обучения
|
||||
case budget_quantity_position = 1;
|
||||
case non_budget_quantity_position = 2;
|
||||
|
||||
public static function fromName(string $name): ?self {
|
||||
return match ($name) {
|
||||
|
||||
@@ -8,6 +8,9 @@ enum CacheKeys: string {
|
||||
case RECENT_POSTS_PREFIX = 'recent_posts_';
|
||||
case POSTS_PREFIX = 'posts_';
|
||||
case EDUCATION_PROGRAM_PREFIX = 'education_program_';
|
||||
case ADMISSION_CAMPAIGNS_PREFIX = 'admission_campaigns_';
|
||||
case DIRECTION_STUDIES = 'direction_studies_';
|
||||
case ADMISSION_PLANS = 'admission_plans_';
|
||||
case EDUCATION_PROGRAMS_PREFIX = 'education_programs_';
|
||||
case ADDITIONAL_EDUCATIONAL_PROGRAM_PREFIX = 'additional_education_program_';
|
||||
case ADDITIONAL_EDUCATIONAL_PROGRAMS_PREFIX = 'additional_education_programs_';
|
||||
|
||||
@@ -28,11 +28,7 @@ class ClientAdditionalEducationController extends Controller
|
||||
|
||||
public function index(Request $request): \Inertia\Response
|
||||
{
|
||||
$cacheKey = md5(serialize([
|
||||
'direction' => $request->input('direction'),
|
||||
'form' => $request->input('form'),
|
||||
'category' => $request->input('category'),
|
||||
]));
|
||||
$cacheKey = md5(serialize($request->all()));
|
||||
|
||||
// Основные данные (кешируются)
|
||||
$directionAdditionalEducations = Cache::remember(
|
||||
@@ -53,6 +49,7 @@ class ClientAdditionalEducationController extends Controller
|
||||
now()->addDay(),
|
||||
function () use ($request) {
|
||||
$query = AdditionalEducationCategory::query()
|
||||
->has('additionalEducations')
|
||||
->WithActivePrograms()
|
||||
->where('is_active', true)
|
||||
->when($request->direction, function ($q, $direction) use ($request) {
|
||||
|
||||
@@ -6,21 +6,14 @@ use App\Enums\BudgetEducation;
|
||||
use App\Enums\CacheKeys;
|
||||
use App\Enums\FormEducation;
|
||||
use App\Enums\LevelEducational;
|
||||
use App\Http\Resources\CampaignDegreeResource;
|
||||
use App\Http\Resources\ClientNavigationResource;
|
||||
use App\Http\Resources\DirectionStudyResource;
|
||||
use App\Http\Resources\EducationalProgramFullResource;
|
||||
use App\Http\Resources\MainSectionResource;
|
||||
use App\Models\AdmissionCampaign;
|
||||
use App\Models\AdmissionPlan;
|
||||
use App\Models\CampaignDegree;
|
||||
use App\Models\DirectionStudy;
|
||||
use App\Models\EducationalProgram;
|
||||
use App\Models\MainSection;
|
||||
use App\Services\App\Seo\SeoPageProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Inertia;
|
||||
|
||||
@@ -36,7 +29,7 @@ class ClientProgramController extends Controller
|
||||
$cacheKeyBudgets = 'education_budgets_list';
|
||||
$cacheKeySeo = 'education_programs_seo';
|
||||
|
||||
$activeCampaign = Cache::remember('active_admission_campaign', now()->addDay(), function () {
|
||||
$activeCampaign = Cache::remember(CacheKeys::ADMISSION_CAMPAIGNS_PREFIX->value, now()->addDay(), function () {
|
||||
return AdmissionCampaign::where('status', 1)->first();
|
||||
});
|
||||
|
||||
@@ -58,13 +51,14 @@ class ClientProgramController extends Controller
|
||||
$seo = Cache::remember($cacheKeySeo, now()->addDay(), function () {
|
||||
return $this->seoPageProvider->getSeoForCurrentPage();
|
||||
});
|
||||
;
|
||||
|
||||
$naprs = Cache::remember($cacheKey, now()->addHours(1), function () use ($request, $activeCampaign) {
|
||||
$naprs = Cache::remember($cacheKey, now()->addHours(), function () use ($request, $activeCampaign) {
|
||||
return DirectionStudyResource::collection(
|
||||
DirectionStudy::query()
|
||||
->withAdmissionCampaignByYear($activeCampaign->academic_year)
|
||||
->withActivePrograms()
|
||||
->with('programs.admission_plans')
|
||||
// ->with('programs.admission_plans')
|
||||
->when($request->input('level'), fn($q, $level) =>
|
||||
$q->where('lvl_edu', LevelEducational::fromName($level)->value))
|
||||
->when($request->input('form'), fn($q, $form) =>
|
||||
@@ -77,6 +71,7 @@ class ClientProgramController extends Controller
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
$data = [
|
||||
'naprs' => $naprs,
|
||||
'campaignName' => $this->getAdmissionCampaignName(),
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Services\App\Cache\AdmissionCampaignCacheService;
|
||||
|
||||
class AdmissionCampaignObserver
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AdmissionCampaignCacheService $admissionCampaignCacheService
|
||||
){}
|
||||
|
||||
public function saved(): void
|
||||
{
|
||||
$this->admissionCampaignCacheService->clearAllCacheByModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Post "updated" event.
|
||||
*/
|
||||
public function updated()
|
||||
{
|
||||
$this->admissionCampaignCacheService->clearAllCacheByModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Очистка кеша при удалении поста.
|
||||
*/
|
||||
public function deleted()
|
||||
{
|
||||
$this->admissionCampaignCacheService->clearAllCacheByModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Post "restored" event.
|
||||
*/
|
||||
public function restored(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Post "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,11 @@ namespace App\Providers;
|
||||
|
||||
use App\Models\AcademicJournal;
|
||||
use App\Models\AdditionalEducation;
|
||||
use App\Models\AdmissionCampaign;
|
||||
use App\Models\AdmissionPlan;
|
||||
use App\Models\ContactWidget;
|
||||
use App\Models\Department;
|
||||
use App\Models\DirectionStudy;
|
||||
use App\Models\Division;
|
||||
use App\Models\EducationalProgram;
|
||||
use App\Models\Event;
|
||||
@@ -21,8 +24,11 @@ use App\Models\SubSection;
|
||||
use App\Models\User;
|
||||
use App\Observers\AcademicJournalObserver;
|
||||
use App\Observers\AdditionalEducationObserver;
|
||||
use App\Observers\AdmissionCampaignObserver;
|
||||
use App\Observers\AdmissionPlanObserver;
|
||||
use App\Observers\ContactWidgetObserver;
|
||||
use App\Observers\DepartmentObserver;
|
||||
use App\Observers\DirectionStudyObserver;
|
||||
use App\Observers\DivisionObserver;
|
||||
use App\Observers\EducationalProgramObserver;
|
||||
use App\Observers\EventObserver;
|
||||
@@ -93,6 +99,9 @@ class AppServiceProvider extends ServiceProvider
|
||||
Schedule::observe(ScheduleObserver::class);
|
||||
ContactWidget::observe(ContactWidgetObserver::class);
|
||||
PageReferenceList::observe(PageReferenceListObserver::class);
|
||||
AdmissionPlan::observe(AdmissionCampaignObserver::class);
|
||||
AdmissionCampaign::observe(AdmissionCampaignObserver::class);
|
||||
DirectionStudy::observe(AdmissionCampaignObserver::class);
|
||||
}
|
||||
|
||||
private static function setLocaleTime() : void {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class AdmissionCampaignCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
/**
|
||||
* Clear cache for specific post
|
||||
*/
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all cache related to posts
|
||||
*/
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::ADMISSION_CAMPAIGNS_PREFIX->value.'*');
|
||||
$this->clearCacheByPrefix(CacheKeys::DIRECTION_STUDIES->value.'*');
|
||||
$this->clearCacheByPrefix(CacheKeys::ADMISSION_PLANS->value.'*');
|
||||
$this->clearCacheByPrefix(CacheKeys::EDUCATION_PROGRAM_PREFIX->value.'*');
|
||||
$this->clearCacheByPrefix('education_'.'*');
|
||||
}
|
||||
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user