Action on Cached Items

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/546/head
Maxence Lange 2019-05-29 19:56:42 -01:00
rodzic 2714c14e09
commit dad67f6de0
6 zmienionych plików z 21 dodań i 10 usunięć

8
composer.lock wygenerowano
Wyświetl plik

@ -12,12 +12,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/daita/my-small-php-tools.git", "url": "https://github.com/daita/my-small-php-tools.git",
"reference": "732d54bca742e3ecdb2b544589550a37172c1258" "reference": "6e8f346a2ee488655316d1e4139c27417d6b7e4d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/732d54bca742e3ecdb2b544589550a37172c1258", "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/6e8f346a2ee488655316d1e4139c27417d6b7e4d",
"reference": "732d54bca742e3ecdb2b544589550a37172c1258", "reference": "6e8f346a2ee488655316d1e4139c27417d6b7e4d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -40,7 +40,7 @@
} }
], ],
"description": "My small PHP Tools", "description": "My small PHP Tools",
"time": "2019-05-27T17:53:41+00:00" "time": "2019-05-29T20:52:05+00:00"
}, },
{ {
"name": "friendica/json-ld", "name": "friendica/json-ld",

Wyświetl plik

@ -755,7 +755,6 @@ class CoreRequestBuilder {
* @param array $data * @param array $data
* *
* @return StreamAction * @return StreamAction
* @throws InvalidResourceException
*/ */
protected function parseStreamActionsLeftJoin(array $data): StreamAction { protected function parseStreamActionsLeftJoin(array $data): StreamAction {
$new = []; $new = [];

Wyświetl plik

@ -524,7 +524,7 @@ class StreamRequest extends StreamRequestBuilder {
} }
$cache = '[]'; $cache = '[]';
if ($stream->gotCache()) { if ($stream->hasCache()) {
$cache = json_encode($stream->getCache(), JSON_UNESCAPED_SLASHES); $cache = json_encode($stream->getCache(), JSON_UNESCAPED_SLASHES);
} }

Wyświetl plik

@ -410,6 +410,18 @@ class StreamRequestBuilder extends CoreRequestBuilder {
try { try {
$action = $this->parseStreamActionsLeftJoin($data); $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); $item->setAction($action);
} catch (InvalidResourceException $e) { } catch (InvalidResourceException $e) {
} }

Wyświetl plik

@ -228,7 +228,7 @@ class Stream extends ACore implements JsonSerializable {
/** /**
* @return bool * @return bool
*/ */
public function gotCache(): bool { public function hasCache(): bool {
return ($this->cache !== null); return ($this->cache !== null);
} }
@ -254,7 +254,7 @@ class Stream extends ACore implements JsonSerializable {
public function addCacheItem(string $url): Stream { public function addCacheItem(string $url): Stream {
$cacheItem = new CacheItem($url); $cacheItem = new CacheItem($url);
if (!$this->gotCache()) { if (!$this->hasCache()) {
$this->setCache(new Cache()); $this->setCache(new Cache());
} }
@ -373,7 +373,7 @@ class Stream extends ACore implements JsonSerializable {
$result, $result,
[ [
'action' => ($this->hasAction()) ? $this->getAction() : [], 'action' => ($this->hasAction()) ? $this->getAction() : [],
'cache' => ($this->gotCache()) ? $this->getCache() : '', 'cache' => ($this->hasCache()) ? $this->getCache() : '',
'publishedTime' => $this->getPublishedTime() 'publishedTime' => $this->getPublishedTime()
] ]
); );

Wyświetl plik

@ -177,7 +177,7 @@ class StreamQueueService {
return; return;
} }
if (!$stream->gotCache()) { if (!$stream->hasCache()) {
$this->deleteCache($queue); $this->deleteCache($queue);
return; return;