[MEDIA][CACHE] Cache avatar queries and delete stale values; small refactoring

This commit is contained in:
Hugo Sales
2020-08-19 15:32:45 +00:00
committed by Hugo Sales
parent e3c5d7e5dc
commit 9649bec01e
4 changed files with 39 additions and 6 deletions

View File

@@ -238,7 +238,7 @@ class File extends Entity
],
'primary key' => ['id'],
'unique keys' => [
'file_file_key' => ['file_hash', 'actor_id'],
// 'file_file_key' => ['file_hash', 'actor_id'],
],
'indexes' => [
'file_filehash_idx' => ['file_hash'],

View File

@@ -205,17 +205,23 @@ class GSActor extends Entity
public static function getFromId(int $id): ?self
{
return DB::find('gsactor', ['id' => $id]);
return Cache::get('gsactor-id-' . $id, function () use ($id) {
return DB::find('gsactor', ['id' => $id]);
});
}
public static function getFromNickname(string $nickname): ?self
{
return DB::findOneBy('gsactor', ['nickname' => $nickname]);
return Cache::get('gsactor-nick-' . $nickname, function () use ($nickname) {
return DB::findOneBy('gsactor', ['nickname' => $nickname]);
});
}
public static function getNicknameFromId(int $id): string
{
return self::getFromId($id)->getNickname();
return Cache::get('gsactor-nick-id-' . $id, function () use ($id) {
return self::getFromId($id)->getNickname();
});
}
public function getSelfTags(): array