Browse Source

[ENTITY][Note][CONFIG] Use getListPartialCache for getReplies. Add feeds/cached_replies config entry to control how many replies get cached

v3
Hugo Sales 5 months ago
parent
commit
d5f90a1206
Signed by untrusted user: someonewithpc <hugo@hsal.es> GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 17 additions and 8 deletions
  1. +1
    -0
      social.yaml
  2. +16
    -8
      src/Entity/Note.php

+ 1
- 0
social.yaml View File

@@ -275,6 +275,7 @@ parameters:

feeds:
entries_per_page: 32
cached_replies: 8

plugin_tree_notes:
feed_replies: 3


+ 16
- 8
src/Entity/Note.php View File

@@ -28,10 +28,10 @@ use App\Core\Cache;
use App\Core\DB\DB;
use App\Core\Entity;
use App\Core\Event;
use function App\Core\I18n\_m;
use App\Core\Log;
use App\Core\Router\Router;
use App\Core\VisibilityScope;
use App\Util\Common;
use App\Util\Exception\ClientException;
use App\Util\Exception\NoSuchNoteException;
use App\Util\Formatting;
@@ -39,9 +39,10 @@ use Component\Avatar\Avatar;
use Component\Conversation\Entity\Conversation;
use Component\Language\Entity\Language;
use Component\Notification\Entity\Attention;
use const PREG_SPLIT_NO_EMPTY;
use DateTimeInterface;
use function App\Core\I18n\_m;
use function mb_substr;
use const PREG_SPLIT_NO_EMPTY;

/**
* Entity for notes
@@ -406,13 +407,20 @@ class Note extends Entity
*/
public function getReplies(int $offset = 0, int $limit = null): array
{
return Cache::getList(self::cacheKeys($this->getId())['replies'],
fn () => DB::findBy(self::class, [
'reply_to' => $this->getId()
],
order_by: ['created' => 'ASC', 'id' => 'ASC']),
return Cache::getListPartialCache(
key: self::cacheKeys($this->getId())['replies'],
calculate: function (int $limit, int $offset) {
return DB::findBy(
self::class,
['reply_to' => $this->getId()],
order_by: ['created' => 'ASC', 'id' => 'ASC'],
limit: $limit,
offset: $offset
);
},
max_cache_count: Common::config('feeds', 'cached_replies'),
left: $offset,
right: $limit
right: $limit - $offset
);
}



Loading…
Cancel
Save