update action cache

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/1704/head
Maxence Lange 2023-03-27 17:47:51 -01:00
rodzic 1ca33be580
commit 9ce28af659
3 zmienionych plików z 37 dodań i 3 usunięć

Wyświetl plik

@ -332,6 +332,23 @@ class StreamRequest extends StreamRequestBuilder {
} }
/**
* @param string $id
*
* @return int
*/
public function countRepliesTo(string $id): int {
$qb = $this->countNotesSelectSql();
$qb->limitToInReplyTo($id, true);
$cursor = $qb->execute();
$data = $cursor->fetch();
$cursor->closeCursor();
return $this->getInt('count', $data, 0);
}
/** /**
* @param string $actorId * @param string $actorId
* *

Wyświetl plik

@ -90,6 +90,7 @@ class NoteInterface extends AbstractActivityPubInterface implements IActivityPub
$this->streamRequest->getStreamById($note->getId()); $this->streamRequest->getStreamById($note->getId());
} catch (StreamNotFoundException $e) { } catch (StreamNotFoundException $e) {
$this->streamRequest->save($note); $this->streamRequest->save($note);
$this->updateDetails($note);
$this->pushService->onNewStream($note->getId()); $this->pushService->onNewStream($note->getId());
} }
} }
@ -98,4 +99,20 @@ class NoteInterface extends AbstractActivityPubInterface implements IActivityPub
/** @var Note $item */ /** @var Note $item */
$this->streamRequest->deleteById($item->getId(), Note::TYPE); $this->streamRequest->deleteById($item->getId(), Note::TYPE);
} }
public function updateDetails(Note $stream): void {
if ($stream->getInReplyTo() === '') {
return;
}
try {
$orig = $this->streamRequest->getStreamById($stream->getInReplyTo());
$count = $this->streamRequest->countRepliesTo($stream->getInReplyTo());
$orig->setDetailInt('replies', $count);
$this->streamRequest->update($orig);
} catch (StreamNotFoundException $e) {
}
}
} }

Wyświetl plik

@ -635,9 +635,9 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
"in_reply_to_id" => null, "in_reply_to_id" => null,
"in_reply_to_account_id" => null, "in_reply_to_account_id" => null,
'mentions' => $this->getMentions(), 'mentions' => $this->getMentions(),
'replies_count' => 0, 'replies_count' => $this->getDetailInt('replies'),
'reblogs_count' => 0, 'reblogs_count' => $this->getDetailInt('boosts'),
'favourites_count' => 0, 'favourites_count' => $this->getDetailInt('likes'),
'favourited' => $favorited, 'favourited' => $favorited,
'reblogged' => $reblogged, 'reblogged' => $reblogged,
'muted' => false, 'muted' => false,