* added caching to watchers

This commit is contained in:
Dávid Danyi 2018-09-13 11:33:06 +02:00
parent 3d42f16c38
commit bb937a664b
2 changed files with 50 additions and 36 deletions

View File

@ -31,6 +31,12 @@ class UpdatePageCachesCommand extends Command
->setDescription('Updates page-cache data for kanban pages'); ->setDescription('Updates page-cache data for kanban pages');
} }
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
* @throws \Exception
*/
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$teams = $this->teamService->listTeams(); $teams = $this->teamService->listTeams();
@ -39,6 +45,7 @@ class UpdatePageCachesCommand extends Command
if (null !== $team->getFilterId()) { if (null !== $team->getFilterId()) {
$this->jiraCollectorService->getKanbanBoard($team->getId(), true); $this->jiraCollectorService->getKanbanBoard($team->getId(), true);
} }
$this->jiraCollectorService->getTeamWatchedIssues($team->getId(), true);
} }
} }
} }

View File

@ -22,6 +22,7 @@ use Zend\Json\Json;
class JiraCollectorService class JiraCollectorService
{ {
const CACHE_KEY_KANBANBOARD = 'kanbanBoard'; const CACHE_KEY_KANBANBOARD = 'kanbanBoard';
const CACHE_KEY_WATCHED = 'watchedIssues';
const BACKLOG_FIELD_DELIMITER = ';'; const BACKLOG_FIELD_DELIMITER = ';';
const EPIC_TICKET_LINK = 'customfield_11711'; const EPIC_TICKET_LINK = 'customfield_11711';
@ -119,21 +120,23 @@ class JiraCollectorService
$kanbanBoard = $this->hydrateKanbanBoard($team, $parsedJsonData); $kanbanBoard = $this->hydrateKanbanBoard($team, $parsedJsonData);
$this->cache->setItem(sprintf("%s-%s", self::CACHE_KEY_KANBANBOARD, $teamName), serialize($kanbanBoard)); $this->cache->setItem(sprintf("%s-%s", self::CACHE_KEY_KANBANBOARD, $teamName), serialize($kanbanBoard));
} else {
$kanbanBoard = unserialize($kanbanBoard);
}
return $kanbanBoard; return $kanbanBoard;
} }
return unserialize($kanbanBoard);
}
/** /**
* @param int $teamId * @param int $teamId
* @param bool $forceReload
* @return array * @return array
* @throws \Exception * @throws \Exception
*/ */
public function getTeamWatchedIssues(int $teamId) public function getTeamWatchedIssues(int $teamId, bool $forceReload = false)
{ {
$team = $this->teamService->getTeam($teamId); $team = $this->teamService->getTeam($teamId);
$teamName = $team->getName();
$watchedIssues = $this->cache->getItem(sprintf("%s-%s", self::CACHE_KEY_WATCHED, $teamName));
if ($forceReload || null === $watchedIssues) {
$members = array_map(function (array $member): string { $members = array_map(function (array $member): string {
return $member['signum']; return $member['signum'];
}, $team->getMembers()); }, $team->getMembers());
@ -167,7 +170,11 @@ class JiraCollectorService
), $response->getStatusCode()); ), $response->getStatusCode());
} }
return $this->hydrateWatchedIssues(Decoder::decode($response->getBody(), Json::TYPE_ARRAY), $members); $watchedIssues = $this->hydrateWatchedIssues(Decoder::decode($response->getBody(), Json::TYPE_ARRAY), $members);
$this->cache->setItem(sprintf("%s-%s", self::CACHE_KEY_KANBANBOARD, $teamName), serialize($watchedIssues));
return $watchedIssues;
}
return unserialize($watchedIssues);
} }
/** /**