kopia lustrzana https://github.com/nextcloud/social
update data instead of delete+save
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/291/head
rodzic
0251b83d1a
commit
2f58b91408
|
|
@ -102,6 +102,45 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* insert cache about an Actor in database.
|
||||||
|
*
|
||||||
|
* @param Person $actor
|
||||||
|
*/
|
||||||
|
public function update(Person $actor) {
|
||||||
|
$qb = $this->getCacheActorsUpdateSql();
|
||||||
|
$qb->set('account', $qb->createNamedParameter($actor->getAccount()))
|
||||||
|
->set('following', $qb->createNamedParameter($actor->getFollowing()))
|
||||||
|
->set('followers', $qb->createNamedParameter($actor->getFollowers()))
|
||||||
|
->set('inbox', $qb->createNamedParameter($actor->getInbox()))
|
||||||
|
->set('shared_inbox', $qb->createNamedParameter($actor->getSharedInbox()))
|
||||||
|
->set('outbox', $qb->createNamedParameter($actor->getOutbox()))
|
||||||
|
->set('featured', $qb->createNamedParameter($actor->getFeatured()))
|
||||||
|
->set('url', $qb->createNamedParameter($actor->getUrl()))
|
||||||
|
->set('preferred_username', $qb->createNamedParameter($actor->getPreferredUsername()))
|
||||||
|
->set('name', $qb->createNamedParameter($actor->getName()))
|
||||||
|
->set('summary', $qb->createNamedParameter($actor->getSummary()))
|
||||||
|
->set('public_key', $qb->createNamedParameter($actor->getPublicKey()))
|
||||||
|
->set('source', $qb->createNamedParameter($actor->getSource()))
|
||||||
|
->set('details', $qb->createNamedParameter(json_encode($actor->getDetails())))
|
||||||
|
->set(
|
||||||
|
'creation',
|
||||||
|
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($actor->gotIcon()) {
|
||||||
|
$iconId = $actor->getIcon()
|
||||||
|
->getId();
|
||||||
|
} else {
|
||||||
|
$iconId = $actor->getIconId();
|
||||||
|
}
|
||||||
|
|
||||||
|
$qb->set('icon_id', $qb->createNamedParameter($iconId));
|
||||||
|
|
||||||
|
$qb->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get Cached version of an Actor, based on the UriId
|
* get Cached version of an Actor, based on the UriId
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,9 @@ class PersonInterface implements IActivityPubInterface {
|
||||||
*/
|
*/
|
||||||
public function getItemById(string $id): ACore {
|
public function getItemById(string $id): ACore {
|
||||||
try {
|
try {
|
||||||
return $this->cacheActorsRequest->getFromId($id);
|
$actor = $this->cacheActorsRequest->getFromId($id);
|
||||||
|
|
||||||
|
return $actor;
|
||||||
} catch (CacheActorDoesNotExistException $e) {
|
} catch (CacheActorDoesNotExistException $e) {
|
||||||
throw new ItemNotFoundException();
|
throw new ItemNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
@ -122,7 +124,12 @@ class PersonInterface implements IActivityPubInterface {
|
||||||
*/
|
*/
|
||||||
public function save(ACore $person) {
|
public function save(ACore $person) {
|
||||||
/** @var Person $person */
|
/** @var Person $person */
|
||||||
$this->actorService->save($person);
|
try {
|
||||||
|
$this->getItemById($person->getId());
|
||||||
|
$this->actorService->update($person);
|
||||||
|
} catch (ItemNotFoundException $e) {
|
||||||
|
$this->actorService->save($person);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,24 @@ class ActorService {
|
||||||
* @param Person $actor
|
* @param Person $actor
|
||||||
*/
|
*/
|
||||||
public function save(Person $actor) {
|
public function save(Person $actor) {
|
||||||
|
$this->cacheDocumentIfNeeded($actor);
|
||||||
|
$this->cacheActorsRequest->save($actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Person $actor
|
||||||
|
*/
|
||||||
|
public function update(Person $actor) {
|
||||||
|
$this->cacheDocumentIfNeeded($actor);
|
||||||
|
$this->cacheActorsRequest->update($actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Person $actor
|
||||||
|
*/
|
||||||
|
private function cacheDocumentIfNeeded(Person $actor) {
|
||||||
if ($actor->gotIcon()) {
|
if ($actor->gotIcon()) {
|
||||||
try {
|
try {
|
||||||
$icon = $this->cacheDocumentsRequest->getBySource(
|
$icon = $this->cacheDocumentsRequest->getBySource(
|
||||||
|
|
@ -135,8 +153,6 @@ class ActorService {
|
||||||
$this->cacheDocumentsRequest->save($actor->getIcon());
|
$this->cacheDocumentsRequest->save($actor->getIcon());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->cacheActorsRequest->save($actor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,6 @@ class CacheActorService {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($refresh) {
|
if ($refresh) {
|
||||||
$this->cacheActorsRequest->deleteFromId($id);
|
|
||||||
throw new CacheActorDoesNotExistException();
|
throw new CacheActorDoesNotExistException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue