remove invalid follows/streams on check

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/691/head
Maxence Lange 2019-08-21 11:22:24 -01:00
rodzic 48e013cb98
commit dbd85cff3b
3 zmienionych plików z 114 dodań i 4 usunięć

Wyświetl plik

@ -92,6 +92,23 @@ class FollowsRequest extends FollowsRequestBuilder {
}
/**
* @return Follow[]
*/
public function getAll(): array {
$qb = $this->getFollowsSelectSql();
$follows = [];
$cursor = $qb->execute();
while ($data = $cursor->fetch()) {
$follows[] = $this->parseFollowsSelectSql($data);
}
$cursor->closeCursor();
return $follows;
}
/**
* @param string $actorId
* @param string $remoteActorId
@ -293,6 +310,15 @@ class FollowsRequest extends FollowsRequestBuilder {
$qb->execute();
}
/**
* @param string $followId
*/
public function deleteFollowById(string $followId) {
$qb = $this->getFollowsDeleteSql();
$this->limitToIdString($qb, $followId);
$qb->execute();
}
}

Wyświetl plik

@ -195,6 +195,27 @@ class StreamRequest extends StreamRequestBuilder {
}
/**
* @return Stream[]
*/
public function getAll(): array {
$qb = $this->getStreamSelectSql();
$streams = [];
$cursor = $qb->execute();
while ($data = $cursor->fetch()) {
try {
$streams[] = $this->parseStreamSelectSql($data);
} catch (Exception $e) {
}
}
$cursor->closeCursor();
return $streams;
}
/**
* @param string $id
* @param bool $asViewer
@ -518,7 +539,8 @@ class StreamRequest extends StreamRequestBuilder {
* @return array
* @throws Exception
*/
public function getTimelineLiked(int $since = 0, int $limit = 5, bool $localOnly = true): array {
public function getTimelineLiked(int $since = 0, int $limit = 5, bool $localOnly = true
): array {
$qb = $this->getStreamSelectSql();
$this->limitPaginate($qb, $since, $limit);

Wyświetl plik

@ -28,7 +28,10 @@ use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\TStringTools;
use Exception;
use GuzzleHttp\Exception\ClientException;
use OCA\Social\Db\CacheActorsRequest;
use OCA\Social\Db\FollowsRequest;
use OCA\Social\Db\StreamRequest;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Model\ActivityPub\Object\Follow;
use OCP\AppFramework\Http;
use OCP\Http\Client\IClientService;
@ -68,11 +71,20 @@ class CheckService {
/** @var IURLGenerator */
private $urlGenerator;
/** @var FollowsRequest */
private $followRequest;
/** @var CacheActorsRequest */
private $cacheActorsRequest;
/** @var StreamRequest */
private $streamRequest;
/** @var ConfigService */
private $configService;
/** @var FollowsRequest */
private $followRequest;
/** @var MiscService */
private $miscService;
/**
@ -84,11 +96,17 @@ class CheckService {
* @param IRequest $request
* @param IURLGenerator $urlGenerator
* @param FollowsRequest $followRequest
* @param CacheActorsRequest $cacheActorsRequest
* @param StreamRequest $streamRequest
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
ICache $cache, IConfig $config, IClientService $clientService, IRequest $request,
IURLGenerator $urlGenerator, FollowsRequest $followRequest, ConfigService $configService
IURLGenerator $urlGenerator, FollowsRequest $followRequest,
CacheActorsRequest $cacheActorsRequest, StreamRequest $streamRequest,
ConfigService $configService,
MiscService $miscService
) {
$this->cache = $cache;
$this->config = $config;
@ -96,7 +114,10 @@ class CheckService {
$this->request = $request;
$this->urlGenerator = $urlGenerator;
$this->followRequest = $followRequest;
$this->cacheActorsRequest = $cacheActorsRequest;
$this->streamRequest = $streamRequest;
$this->configService = $configService;
$this->miscService = $miscService;
}
@ -156,6 +177,8 @@ class CheckService {
public function checkInstallationStatus() {
$this->configService->setCoreValue('public_webfinger', 'social/lib/webfinger.php');
$this->configService->setCoreValue('public_host-meta', 'social/lib/hostmeta.php');
$this->removeInvalidFollows();
$this->removeInvalidNotes();
$this->checkStatusTableFollows();
}
@ -179,6 +202,45 @@ class CheckService {
}
/**
*
*/
public function removeInvalidFollows() {
$count = 0;
$follows = $this->followRequest->getAll();
foreach ($follows as $follow) {
try {
$this->cacheActorsRequest->getFromId($follow->getActorId());
$this->cacheActorsRequest->getFromId($follow->getObjectId());
} catch (CacheActorDoesNotExistException $e) {
$this->followRequest->deleteFollowById($follow->getId());
$count++;
}
}
$this->miscService->log('removeInvalidFollows removed ' . $count . ' entries', 1);
}
/**
*
*/
public function removeInvalidNotes() {
$count = 0;
$streams = $this->streamRequest->getAll();
foreach ($streams as $stream) {
try {
// Check if it's enough for Note, Announce, ...
$this->cacheActorsRequest->getFromId($stream->getAttributedTo());
} catch (CacheActorDoesNotExistException $e) {
$this->streamRequest->deleteStreamById($stream->getId());
$count++;
}
}
$this->miscService->log('removeInvalidNotes removed ' . $count . ' entries', 1);
}
/**
* @param string $base
*