<commit_before><?php

namespace App\Listeners\Groups\GroupUpdated;

use App\Events\Groups\GroupUpdated;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Cache;

class InvalidateUpdatesTeacherCache
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  GroupUpdated  $event
     * @return void
     */
    public function handle(GroupUpdated $event)
    {
        $oldGroup = $event->oldGroup;
        $updatedGroup = $event->updatedGroup;

        if (is_null($updatedGroup) || $oldGroup->is_archived == !$updatedGroup->is_archived ||
            $oldGroup->teacher_id !== $updatedGroup->teacher_id
        ) {
            $cacheKey = 'updates_teacher_' . $oldGroup->teacher_id;
            Cache::forget($cacheKey);
        }
    }
}<commit_msg>make sure we invalidate cache for new teacher also<commit_after><?php

namespace App\Listeners\Groups\GroupUpdated;

use App\Events\Groups\GroupUpdated;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Cache;

class InvalidateUpdatesTeacherCache
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  GroupUpdated  $event
     * @return void
     */
    public function handle(GroupUpdated $event)
    {
        $oldGroup = $event->oldGroup;
        $updatedGroup = $event->updatedGroup;

        $cacheKeyOldTeacher = 'updates_teacher_' . $oldGroup->teacher_id;
        if ($oldGroup->is_archived == !$updatedGroup->is_archived) {
            Cache::forget($cacheKeyOldTeacher);
        }

        if ($oldGroup->teacher_id !== $updatedGroup->teacher_id) {
            Cache::forget($cacheKeyOldTeacher);
            $cacheKeyNewTeacher = 'updates_teacher_' . $updatedGroup->teacher_id;
            Cache::forget($cacheKeyNewTeacher);
        }
    }
}
{'fraction_non_alphanumeric': 0.11865211200759374, 'fraction_numerical': 0.0, 'mean_word_length': 2.548821548821549, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3316113', 'n_tokens_mistral': 645, 'n_tokens_neox': 647, 'n_words': 109}