Skip to content

Commit

Permalink
Added pronoun cache
Browse files Browse the repository at this point in the history
  • Loading branch information
spitfire305 committed Jan 28, 2025
1 parent 947688f commit 6c9ad50
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
34 changes: 33 additions & 1 deletion app/Services/Caches/CharacterCacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ public function genderSuggestion(): array
->pluck('sex')
->all();

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

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

$data = Character::select(DB::raw('pronouns, MAX(created_at) as cmat'))
->groupBy('pronouns')
->whereNotNull('pronouns')
->orderBy('cmat', 'DESC')
->take(10)
->pluck('pronouns')
->all();
$data[] = 'ass';


Cache::put($key, $data, 24 * 3600);
return $data;
Expand All @@ -42,15 +64,25 @@ public function clearSuggestion(): self
$this->genderSuggestionKey()
);

$this->forget(
$this->pronounSuggestionKey()
);
return $this;
}


/**
* Type suggestion cache key
*/
protected function genderSuggestionKey(): string
{
return 'campaign_' . $this->campaign->id . '_character_gender_suggestions';
}

/**
* Type suggestion cache key
*/
protected function pronounSuggestionKey(): string
{
return 'campaign_' . $this->campaign->id . '_character_pronoun_suggestions';
}
}
8 changes: 7 additions & 1 deletion resources/views/cruds/fields/pronouns.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@
:label="__('characters.fields.pronouns')"
:id="$fieldID">
<input id="{{ $fieldID }}" type="text" name="pronouns" value="{!! htmlspecialchars(old('pronouns', str_replace('&amp;', '&', FormCopy::field('pronouns')->child()->string() ?: $model->pronouns ?? ''))) !!}"
placeholder="{{ __('characters.placeholders.pronouns') }}" maxlength="45" spellcheck="true" />
placeholder="{{ __('characters.placeholders.pronouns') }}" maxlength="45" list="entity-pronoun-list" spellcheck="true" />
<datalist id="entity-pronoun-list">
@foreach (\App\Facades\CharacterCache::pronounSuggestion() as $suggestion)
<option value="{{ $suggestion }}">{{ $suggestion }}</option>
@endforeach
</datalist>

</x-forms.field>

0 comments on commit 6c9ad50

Please sign in to comment.