Unverified Commit 76afc0cf authored by Yassine Doghri's avatar Yassine Doghri
Browse files

perf(cache): use deleteMatching method to prevent forgetting cached elements in models

parent 7bcbfb32
Loading
Loading
Loading
Loading
+24 −26
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ class EpisodeController extends BaseController
{
    protected Podcast $podcast;

    protected ?Episode $episode;
    protected Episode $episode;

    public function _remap(string $method, string ...$params): mixed
    {
@@ -253,7 +253,7 @@ class EpisodeController extends BaseController
        $this->episode->is_blocked = $this->request->getPost('block') === 'yes';
        $this->episode->custom_rss_string = $this->request->getPost('custom_rss',);

        $this->episode->updated_by = user_id();
        $this->episode->updated_by = (int) user_id();

        $audioFile = $this->request->getFile('audio_file');
        if ($audioFile !== null && $audioFile->isValid()) {
@@ -268,7 +268,7 @@ class EpisodeController extends BaseController
        $transcriptChoice = $this->request->getPost('transcript-choice');
        if ($transcriptChoice === 'upload-file') {
            $transcriptFile = $this->request->getFile('transcript_file');
            if ($transcriptFile->isValid()) {
            if ($transcriptFile !== null && $transcriptFile->isValid()) {
                $this->episode->transcript_file = $transcriptFile;
                $this->episode->transcript_file_remote_url = null;
            }
@@ -287,7 +287,7 @@ class EpisodeController extends BaseController
        $chaptersChoice = $this->request->getPost('chapters-choice');
        if ($chaptersChoice === 'upload-file') {
            $chaptersFile = $this->request->getFile('chapters_file');
            if ($chaptersFile->isValid()) {
            if ($chaptersFile !== null && $chaptersFile->isValid()) {
                $this->episode->chapters_file = $chaptersFile;
                $this->episode->chapters_file_remote_url = null;
            }
@@ -411,13 +411,11 @@ class EpisodeController extends BaseController
        if ($publishMethod === 'schedule') {
            $scheduledPublicationDate = $this->request->getPost('scheduled_publication_date',);
            if ($scheduledPublicationDate) {
                $scheduledDateUTC = Time::createFromFormat(
                $this->episode->published_at = Time::createFromFormat(
                    'Y-m-d H:i',
                    $scheduledPublicationDate,
                    $this->request->getPost('client_timezone'),
                )->setTimezone('UTC');
                $this->episode->published_at = $scheduledDateUTC;
                $newNote->published_at = $scheduledDateUTC;
            } else {
                $db->transRollback();
                return redirect()
@@ -426,11 +424,11 @@ class EpisodeController extends BaseController
                    ->with('error', 'Schedule date must be set!');
            }
        } else {
            $dateNow = Time::now();
            $this->episode->published_at = $dateNow;
            $newNote->published_at = $dateNow;
            $this->episode->published_at = Time::now();
        }

        $newNote->published_at = $this->episode->published_at;

        $noteModel = new NoteModel();
        if (! $noteModel->addNote($newNote)) {
            $db->transRollback();
@@ -498,20 +496,15 @@ class EpisodeController extends BaseController
        $db = Database::connect();
        $db->transStart();

        $note = (new NoteModel())->getNoteById($this->request->getPost('note_id'),);
        $note->message = $this->request->getPost('message');

        $publishMethod = $this->request->getPost('publication_method');
        if ($publishMethod === 'schedule') {
            $scheduledPublicationDate = $this->request->getPost('scheduled_publication_date',);
            if ($scheduledPublicationDate) {
                $scheduledDateUTC = Time::createFromFormat(
                $this->episode->published_at = Time::createFromFormat(
                    'Y-m-d H:i',
                    $scheduledPublicationDate,
                    $this->request->getPost('client_timezone'),
                )->setTimezone('UTC');
                $this->episode->published_at = $scheduledDateUTC;
                $note->published_at = $scheduledDateUTC;
            } else {
                $db->transRollback();
                return redirect()
@@ -520,11 +513,15 @@ class EpisodeController extends BaseController
                    ->with('error', 'Schedule date must be set!');
            }
        } else {
            $dateNow = Time::now();
            $this->episode->published_at = $dateNow;
            $note->published_at = $dateNow;
            $this->episode->published_at = Time::now();
        }

        $note = (new NoteModel())->getNoteById($this->request->getPost('note_id'),);

        if ($note !== null) {
            $note->message = $this->request->getPost('message');
            $note->published_at = $this->episode->published_at;

            $noteModel = new NoteModel();
            if (! $noteModel->editNote($note)) {
                $db->transRollback();
@@ -533,6 +530,7 @@ class EpisodeController extends BaseController
                    ->withInput()
                    ->with('errors', $noteModel->errors());
            }
        }

        $episodeModel = new EpisodeModel();
        if (! $episodeModel->update($this->episode->id, $this->episode)) {
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class EpisodeController extends BaseController
        }

        if (
            ($this->episode = (new EpisodeModel())->getEpisodeBySlug($this->podcast->id, $params[1],)) !== null
            ($this->episode = (new EpisodeModel())->getEpisodeBySlug($params[0], $params[1],)) !== null
        ) {
            unset($params[1]);
            unset($params[0]);
+3 −5
Original line number Diff line number Diff line
@@ -57,10 +57,8 @@ class FakePodcastsAnalyticsSeeder extends Seeder
                $analyticsPodcastsByRegion = [];

                $episodes = (new EpisodeModel())
                    ->where([
                        'podcast_id' => $podcast->id,
                        'DATE(published_at) <=' => date('Y-m-d', $date),
                    ])
                    ->where('podcast_id', $podcast->id)
                    ->where('`published_at` <= NOW()', null, false)
                    ->findAll();
                foreach ($episodes as $episode) {
                    $age = floor(($date - strtotime($episode->published_at)) / 86400,);
@@ -110,7 +108,7 @@ class FakePodcastsAnalyticsSeeder extends Seeder
                                ? 'N/A'
                                : $city->country->isoCode;

                            $regionCode = $city->subdivisions[0]->isoCode === null
                            $regionCode = $city->subdivisions === []
                                ? 'N/A'
                                : $city->subdivisions[0]->isoCode;
                            $latitude = round($city->location->latitude, 3);
+2 −4
Original line number Diff line number Diff line
@@ -196,10 +196,8 @@ class FakeWebsiteAnalyticsSeeder extends Seeder
                $websiteByReferer = [];

                $episodes = (new EpisodeModel())
                    ->where([
                        'podcast_id' => $podcast->id,
                        'DATE(published_at) <=' => date('Y-m-d', $date),
                    ])
                    ->where('podcast_id', $podcast->id)
                    ->where('`published_at` <= NOW()', null, false)
                    ->findAll();
                foreach ($episodes as $episode) {
                    $age = floor(($date - strtotime($episode->published_at)) / 86400,);
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class EpisodeController extends BaseController
        }

        if (
            ($this->episode = (new EpisodeModel())->getEpisodeBySlug($this->podcast->id, $params[1],)) !== null
            ($this->episode = (new EpisodeModel())->getEpisodeBySlug($params[0], $params[1],)) !== null
        ) {
            unset($params[1]);
            unset($params[0]);
Loading