kopia lustrzana https://github.com/nextcloud/social
update cache in stream
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/632/head
rodzic
623facfb04
commit
b8f3525600
|
@ -109,6 +109,9 @@ class QueueProcess extends Base {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param OutputInterface $output
|
||||
*/
|
||||
private function processRequestQueue(OutputInterface $output) {
|
||||
$total = 0;
|
||||
$requests = $this->requestQueueService->getRequestStandby($total);
|
||||
|
|
|
@ -380,6 +380,7 @@ class LocalController extends Controller {
|
|||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param int $since
|
||||
* @param int $limit
|
||||
|
|
|
@ -76,8 +76,8 @@ class CacheDocumentsRequestBuilder extends CoreRequestBuilder {
|
|||
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
$qb->select(
|
||||
'cd.id', 'cd.type', 'cd.media_type', 'cd.mime_type', 'cd.url', 'cd.local_copy',
|
||||
'cd.public', 'cd.error', 'cd.creation', 'cd.caching'
|
||||
'cd.id', 'cd.type', 'cd.parent_id', 'cd.media_type', 'cd.mime_type', 'cd.url',
|
||||
'cd.local_copy', 'cd.public', 'cd.error', 'cd.creation', 'cd.caching'
|
||||
)
|
||||
->from(self::TABLE_CACHE_DOCUMENTS, 'cd');
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ use OCA\Social\Exceptions\StreamNotFoundException;
|
|||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||
use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification;
|
||||
use OCA\Social\Model\ActivityPub\Object\Document;
|
||||
use OCA\Social\Model\ActivityPub\Object\Note;
|
||||
use OCA\Social\Model\ActivityPub\Stream;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
|
@ -131,6 +132,54 @@ class StreamRequest extends StreamRequestBuilder {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Document $document
|
||||
*/
|
||||
public function updateAttachments(Document $document) {
|
||||
$qb = $this->getStreamSelectSql();
|
||||
$this->limitToIdString($qb, $document->getParentId());
|
||||
|
||||
$cursor = $qb->execute();
|
||||
$data = $cursor->fetch();
|
||||
$cursor->closeCursor();
|
||||
|
||||
if ($data === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$new = $this->updateAttachmentInList($document, $this->getArray('attachments', $data, []));
|
||||
|
||||
$qb = $this->getStreamUpdateSql();
|
||||
$qb->set(
|
||||
'attachments', $qb->createNamedParameter(json_encode($new, JSON_UNESCAPED_SLASHES))
|
||||
);
|
||||
$this->limitToIdString($qb, $document->getParentId());
|
||||
|
||||
$qb->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Document $document
|
||||
* @param array $attachments
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function updateAttachmentInList(Document $document, array $attachments): array {
|
||||
$new = [];
|
||||
foreach ($attachments as $attachment) {
|
||||
$tmp = new Document();
|
||||
$tmp->importFromDatabase($attachment);
|
||||
if ($tmp->getId() === $document->getId()) {
|
||||
$new[] = $document;
|
||||
} else {
|
||||
$new[] = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $itemId
|
||||
* @param string $to
|
||||
|
@ -223,7 +272,8 @@ class StreamRequest extends StreamRequestBuilder {
|
|||
* @throws SocialAppConfigException
|
||||
* @throws StreamNotFoundException
|
||||
*/
|
||||
public function getStreamByObjectId(string $objectId, string $type, string $subType = ''): Stream {
|
||||
public function getStreamByObjectId(string $objectId, string $type, string $subType = ''
|
||||
): Stream {
|
||||
if ($objectId === '') {
|
||||
throw new StreamNotFoundException('missing objectId');
|
||||
};
|
||||
|
@ -702,6 +752,5 @@ class StreamRequest extends StreamRequestBuilder {
|
|||
$qb->andWhere($filter);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -502,8 +502,8 @@ class CurlService {
|
|||
$this->parseRequestResultCurl($curl, $request);
|
||||
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
$contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
|
||||
$request->setContentType(($contentType === null) ? '' : $contentType);
|
||||
$type = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
|
||||
$request->setContentType((is_null($type) || is_bool($type)) ? '' : $type);
|
||||
$request->setResultCode($code);
|
||||
|
||||
$this->parseRequestResultCode301($code, $request);
|
||||
|
|
|
@ -36,9 +36,11 @@ use Exception;
|
|||
use OCA\Social\AP;
|
||||
use OCA\Social\Db\ActorsRequest;
|
||||
use OCA\Social\Db\CacheDocumentsRequest;
|
||||
use OCA\Social\Db\StreamRequest;
|
||||
use OCA\Social\Exceptions\CacheContentException;
|
||||
use OCA\Social\Exceptions\CacheContentMimeTypeException;
|
||||
use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
|
||||
use OCA\Social\Exceptions\ItemAlreadyExistsException;
|
||||
use OCA\Social\Exceptions\ItemUnknownException;
|
||||
use OCA\Social\Exceptions\RequestContentException;
|
||||
use OCA\Social\Exceptions\RequestNetworkException;
|
||||
|
@ -74,6 +76,8 @@ class DocumentService {
|
|||
/** @var ActorsRequest */
|
||||
private $actorRequest;
|
||||
|
||||
/** @var StreamRequest */
|
||||
private $streamRequest;
|
||||
|
||||
/** @var CacheDocumentService */
|
||||
private $cacheService;
|
||||
|
@ -91,19 +95,20 @@ class DocumentService {
|
|||
* @param IUrlGenerator $urlGenerator
|
||||
* @param CacheDocumentsRequest $cacheDocumentsRequest
|
||||
* @param ActorsRequest $actorRequest
|
||||
* @param StreamRequest $streamRequest
|
||||
* @param CacheDocumentService $cacheService
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IUrlGenerator $urlGenerator, CacheDocumentsRequest $cacheDocumentsRequest,
|
||||
ActorsRequest $actorRequest,
|
||||
CacheDocumentService $cacheService,
|
||||
ConfigService $configService, MiscService $miscService
|
||||
ActorsRequest $actorRequest, StreamRequest $streamRequest,
|
||||
CacheDocumentService $cacheService, ConfigService $configService, MiscService $miscService
|
||||
) {
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->cacheDocumentsRequest = $cacheDocumentsRequest;
|
||||
$this->actorRequest = $actorRequest;
|
||||
$this->streamRequest = $streamRequest;
|
||||
$this->configService = $configService;
|
||||
$this->cacheService = $cacheService;
|
||||
$this->miscService = $miscService;
|
||||
|
@ -143,6 +148,8 @@ class DocumentService {
|
|||
$document->setLocalCopy($localCopy);
|
||||
$this->cacheDocumentsRequest->endCaching($document);
|
||||
|
||||
$this->streamRequest->updateAttachments($document);
|
||||
|
||||
return $document;
|
||||
} catch (CacheContentMimeTypeException $e) {
|
||||
$this->miscService->log(
|
||||
|
@ -234,6 +241,7 @@ class DocumentService {
|
|||
* @throws SocialAppConfigException
|
||||
* @throws UrlCloudException
|
||||
* @throws ItemUnknownException
|
||||
* @throws ItemAlreadyExistsException
|
||||
*/
|
||||
public function cacheLocalAvatarByUsername(Person $actor): string {
|
||||
$url = $this->urlGenerator->linkToRouteAbsolute(
|
||||
|
|
Ładowanie…
Reference in New Issue