Skip to content

Commit

Permalink
don't double fetch from redis for transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko committed Dec 18, 2024
1 parent 715db03 commit dd68826
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions app/Models/Beatmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Exceptions\InvariantException;
use App\Jobs\EsDocument;
use App\Libraries\Transactions\AfterCommit;
use App\Traits\Memoizes;
use DB;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
Expand Down Expand Up @@ -53,7 +54,7 @@
*/
class Beatmap extends Model implements AfterCommit
{
use SoftDeletes;
use Memoizes, SoftDeletes;

public $convert = false;

Expand Down Expand Up @@ -350,11 +351,15 @@ public function status()

public function topTagIds()
{
return cache_remember_mutexed(
"beatmap_top_tag_ids:{$this->getKey()}",
$GLOBALS['cfg']['osu']['tags']['beatmap_tags_cache_duration'],
[],
fn () => BeatmapTag::topTagIdsQuery($this->getKey())->get()->toArray(),
// TODO: Add option to multi query when beatmapset requests all tags for beatmaps?
return $this->memoize(
__FUNCTION__,
fn () => cache_remember_mutexed(
"beatmap_top_tag_ids:{$this->getKey()}",
$GLOBALS['cfg']['osu']['tags']['beatmap_tags_cache_duration'],
[],
fn () => BeatmapTag::topTagIdsQuery($this->getKey())->get()->toArray(),
),
);
}

Expand Down

0 comments on commit dd68826

Please sign in to comment.