summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-05-29 19:56:42 -0100
committerMaxence Lange <maxence@artificial-owl.com>2019-05-29 19:56:42 -0100
commitdad67f6de04e1af8506a26beba95c1a58c2be547 (patch)
treea0e7e8892b5f23ee1fb37169482ddb5b4ddbcdd3 /lib
parent2714c14e09bc5464cb5593ebcf0cd8d7774c042d (diff)
Action on Cached Items
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Db/CoreRequestBuilder.php1
-rw-r--r--lib/Db/StreamRequest.php2
-rw-r--r--lib/Db/StreamRequestBuilder.php12
-rw-r--r--lib/Model/ActivityPub/Stream.php6
-rw-r--r--lib/Service/StreamQueueService.php2
5 files changed, 17 insertions, 6 deletions
diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php
index 640e6316..a8cb3009 100644
--- a/lib/Db/CoreRequestBuilder.php
+++ b/lib/Db/CoreRequestBuilder.php
@@ -755,7 +755,6 @@ class CoreRequestBuilder {
* @param array $data
*
* @return StreamAction
- * @throws InvalidResourceException
*/
protected function parseStreamActionsLeftJoin(array $data): StreamAction {
$new = [];
diff --git a/lib/Db/StreamRequest.php b/lib/Db/StreamRequest.php
index 1555c19a..2fd8cb21 100644
--- a/lib/Db/StreamRequest.php
+++ b/lib/Db/StreamRequest.php
@@ -524,7 +524,7 @@ class StreamRequest extends StreamRequestBuilder {
}
$cache = '[]';
- if ($stream->gotCache()) {
+ if ($stream->hasCache()) {
$cache = json_encode($stream->getCache(), JSON_UNESCAPED_SLASHES);
}
diff --git a/lib/Db/StreamRequestBuilder.php b/lib/Db/StreamRequestBuilder.php
index f4cbbe61..f5358bcc 100644
--- a/lib/Db/StreamRequestBuilder.php
+++ b/lib/Db/StreamRequestBuilder.php
@@ -410,6 +410,18 @@ class StreamRequestBuilder extends CoreRequestBuilder {
try {
$action = $this->parseStreamActionsLeftJoin($data);
+ if ($item->hasCache()) {
+ $cache = $item->getCache();
+ if ($cache->hasItem($action->getStreamId())) {
+ $cachedItem = $item->getCache()
+ ->getItem($action->getStreamId());
+ $cachedObject = $cachedItem->getObject();
+ $cachedObject['action'] = $action;
+ $cachedItem->setContent(json_encode($cachedObject));
+ $cache->updateItem($cachedItem, false);
+ }
+ }
+
$item->setAction($action);
} catch (InvalidResourceException $e) {
}
diff --git a/lib/Model/ActivityPub/Stream.php b/lib/Model/ActivityPub/Stream.php
index 8c40d0bf..3cf7a5cc 100644
--- a/lib/Model/ActivityPub/Stream.php
+++ b/lib/Model/ActivityPub/Stream.php
@@ -228,7 +228,7 @@ class Stream extends ACore implements JsonSerializable {
/**
* @return bool
*/
- public function gotCache(): bool {
+ public function hasCache(): bool {
return ($this->cache !== null);
}
@@ -254,7 +254,7 @@ class Stream extends ACore implements JsonSerializable {
public function addCacheItem(string $url): Stream {
$cacheItem = new CacheItem($url);
- if (!$this->gotCache()) {
+ if (!$this->hasCache()) {
$this->setCache(new Cache());
}
@@ -373,7 +373,7 @@ class Stream extends ACore implements JsonSerializable {
$result,
[
'action' => ($this->hasAction()) ? $this->getAction() : [],
- 'cache' => ($this->gotCache()) ? $this->getCache() : '',
+ 'cache' => ($this->hasCache()) ? $this->getCache() : '',
'publishedTime' => $this->getPublishedTime()
]
);
diff --git a/lib/Service/StreamQueueService.php b/lib/Service/StreamQueueService.php
index a3308eca..ab14666b 100644
--- a/lib/Service/StreamQueueService.php
+++ b/lib/Service/StreamQueueService.php
@@ -177,7 +177,7 @@ class StreamQueueService {
return;
}
- if (!$stream->gotCache()) {
+ if (!$stream->hasCache()) {
$this->deleteCache($queue);
return;