Preparing state:cache to support relative GUIDs. related to #69

This commit is contained in:
Abdulmhsen B. A. A
2022-05-05 03:16:08 +03:00
parent 7e35eecfea
commit a2e271b201
3 changed files with 39 additions and 43 deletions

View File

@@ -7,7 +7,6 @@ namespace App\Libs\Servers;
use App\Libs\Config;
use App\Libs\Container;
use App\Libs\Entity\StateInterface;
use App\Libs\Guid;
use App\Libs\HttpException;
use DateTimeInterface;
use Psr\Http\Message\ServerRequestInterface;
@@ -147,18 +146,12 @@ class EmbyServer extends JellyfinServer
$providersId = ag($json, 'Item.ProviderIds', []);
$guids = $this->getGuids($providersId, $type);
foreach (Guid::fromArray($guids)->getPointers() as $guid) {
$this->cacheData[$guid] = ag($json, 'Item.Id');
}
$row = [
'type' => $type,
'updated' => time(),
'watched' => $isWatched,
'meta' => $meta,
...$guids
...$this->getGuids($providersId, $type)
];
$entity = Container::get(StateInterface::class)::fromArray($row)->setIsTainted($isTainted);
@@ -178,6 +171,10 @@ class EmbyServer extends JellyfinServer
);
}
foreach ($entity->getPointers() as $guid) {
$this->cacheData[$guid] = ag($json, 'item.Id');
}
if (false === $isTainted && (true === Config::get('webhook.debug') || null !== ag(
$request->getQueryParams(),
'debug'

View File

@@ -323,18 +323,12 @@ class JellyfinServer implements ServerInterface
$meta['parent'] = $this->getEpisodeParent(ag($json, 'ItemId'), ag($json, 'SeriesName'));
}
$guids = $this->getGuids($providersId, $type);
foreach (Guid::fromArray($guids)->getPointers() as $guid) {
$this->cacheData[$guid] = ag($json, 'Item.ItemId');
}
$row = [
'type' => $type,
'updated' => time(),
'watched' => (int)(bool)ag($json, 'Played', ag($json, 'PlayedToCompletion', 0)),
'meta' => $meta,
...$guids
...$this->getGuids($providersId, $type)
];
$entity = Container::get(StateInterface::class)::fromArray($row)->setIsTainted($isTainted);
@@ -354,6 +348,10 @@ class JellyfinServer implements ServerInterface
);
}
foreach ($entity->getPointers() as $guid) {
$this->cacheData[$guid] = ag($json, 'Item.ItemId');
}
if (false === $isTainted && (true === Config::get('webhook.debug') || null !== ag(
$request->getQueryParams(),
'debug'
@@ -1250,7 +1248,7 @@ class JellyfinServer implements ServerInterface
);
continue;
}
$this->processForCache($type, $entity);
$this->processForCache($entity, $type, $cName);
}
} catch (PathNotFoundException $e) {
$this->logger->error(
@@ -1308,7 +1306,7 @@ class JellyfinServer implements ServerInterface
]
);
},
includeParent: false,
includeParent: true,
);
}
@@ -1553,17 +1551,21 @@ class JellyfinServer implements ServerInterface
}
}
protected function processForCache(string $type, StdClass $item): void
protected function processForCache(StdClass $item, string $type, string $library): void
{
try {
if (!$this->hasSupportedIds((array)($item->ProviderIds ?? []))) {
if ('show' === $type) {
$this->processShow($item, $library);
return;
}
$guids = $this->getGuids((array)($item->ProviderIds ?? []), $type);
foreach (Guid::fromArray($guids)->getPointers() as $guid) {
$this->cacheData[$guid] = $item->Id;
$date = $item->UserData?->LastPlayedDate ?? $item->DateCreated ?? $item->PremiereDate ?? null;
if (null === $date) {
return;
}
$this->createEntity($item, $type);
} catch (Throwable $e) {
$this->logger->error($e->getMessage(), [
'file' => $e->getFile(),

View File

@@ -366,12 +366,6 @@ class PlexServer implements ServerInterface
];
}
$guids = $this->getGuids($json['Metadata']['Guid'] ?? [], $type);
foreach (Guid::fromArray($guids)->getPointers() as $guid) {
$this->cacheData[$guid] = ag($json, 'Metadata.guid');
}
if (StateInterface::TYPE_EPISODE === $type) {
$parentId = ag($json, 'Metadata.grandparentRatingKey', fn() => ag($json, 'Metadata.parentRatingKey'));
$meta['parent'] = null !== $parentId ? $this->getEpisodeParent($parentId) : [];
@@ -382,7 +376,7 @@ class PlexServer implements ServerInterface
'updated' => time(),
'watched' => (int)(bool)ag($json, 'Metadata.viewCount', 0),
'meta' => $meta,
...$guids
...$this->getGuids($json['Metadata']['Guid'] ?? [], $type)
];
$entity = Container::get(StateInterface::class)::fromArray($row)->setIsTainted($isTainted);
@@ -402,6 +396,10 @@ class PlexServer implements ServerInterface
);
}
foreach ($entity->getPointers() as $guid) {
$this->cacheData[$guid] = ag($json, 'Metadata.guid');
}
if (false !== $isTainted && (true === Config::get('webhook.debug') || null !== ag(
$request->getQueryParams(),
'debug'
@@ -1274,7 +1272,8 @@ class PlexServer implements ServerInterface
);
continue;
}
$this->processForCache($type, $entity);
$this->processForCache($entity, $type, $cName);
}
} catch (PathNotFoundException $e) {
$this->logger->error(
@@ -1336,7 +1335,7 @@ class PlexServer implements ServerInterface
]
);
},
includeParent: false
includeParent: true
);
}
@@ -1551,7 +1550,6 @@ class PlexServer implements ServerInterface
);
}
$entity = $this->createEntity($item, $type);
$date = (int)($item->lastViewedAt ?? $item->updatedAt ?? $item->addedAt ?? 0);
@@ -1561,6 +1559,8 @@ class PlexServer implements ServerInterface
return;
}
$entity = $this->createEntity($item, $type);
if (!$entity->hasGuids()) {
if (null === ($item->Guid ?? null)) {
$item->Guid = [['id' => $item->guid]];
@@ -1600,24 +1600,21 @@ class PlexServer implements ServerInterface
}
}
protected function processForCache(string $type, StdClass $item): void
protected function processForCache(StdClass $item, string $type, string $library): void
{
try {
if (null === ($item->Guid ?? null)) {
$item->Guid = [['id' => $item->guid]];
} else {
$item->Guid[] = ['id' => $item->guid];
}
if (!$this->hasSupportedIds($item->Guid)) {
if ('show' === $type) {
$this->processShow($item, $library);
return;
}
$guids = $this->getGuids($item->Guid ?? [], $type);
$date = (int)($item->lastViewedAt ?? $item->updatedAt ?? $item->addedAt ?? 0);
foreach (Guid::fromArray($guids)->getPointers() as $guid) {
$this->cacheData[$guid] = $item->guid;
if (0 === $date) {
return;
}
$this->createEntity($item, $type);
} catch (Throwable $e) {
$this->logger->error($e->getMessage(), [
'file' => $e->getFile(),