* 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');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
* @throws \Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$teams = $this->teamService->listTeams();
@ -39,6 +45,7 @@ class UpdatePageCachesCommand extends Command
if (null !== $team->getFilterId()) {
$this->jiraCollectorService->getKanbanBoard($team->getId(), true);
}
$this->jiraCollectorService->getTeamWatchedIssues($team->getId(), true);
}
}
}

View File

@ -22,6 +22,7 @@ use Zend\Json\Json;
class JiraCollectorService
{
const CACHE_KEY_KANBANBOARD = 'kanbanBoard';
const CACHE_KEY_WATCHED = 'watchedIssues';
const BACKLOG_FIELD_DELIMITER = ';';
const EPIC_TICKET_LINK = 'customfield_11711';
@ -119,55 +120,61 @@ class JiraCollectorService
$kanbanBoard = $this->hydrateKanbanBoard($team, $parsedJsonData);
$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 bool $forceReload
* @return array
* @throws \Exception
*/
public function getTeamWatchedIssues(int $teamId)
public function getTeamWatchedIssues(int $teamId, bool $forceReload = false)
{
$team = $this->teamService->getTeam($teamId);
$members = array_map(function(array $member): string {
return $member['signum'];
}, $team->getMembers());
$preparedMembers = sprintf('"%s"', implode('","', $members));
$filter = sprintf(
self::WATCH_FILTER,
sprintf('"%s"', implode('","', self::IGNORED_STATUSES)),
$preparedMembers, $preparedMembers
);
$user = $this->config->get('jira.user');
$password = $this->config->get('jira.password');
/** @var Config $kanbanBoardUriParams */
$jiraWatchedIssues = $this->config->get('url.jiraWatchedIssues');
$kanbanBoardFilterFields = [
'assignee',
'summary',
'comment',
];
$issueFields = implode(",", $kanbanBoardFilterFields);
$jiraIssueUri = sprintf($jiraWatchedIssues, $filter, $issueFields);
$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 {
return $member['signum'];
}, $team->getMembers());
$preparedMembers = sprintf('"%s"', implode('","', $members));
$filter = sprintf(
self::WATCH_FILTER,
sprintf('"%s"', implode('","', self::IGNORED_STATUSES)),
$preparedMembers, $preparedMembers
);
$user = $this->config->get('jira.user');
$password = $this->config->get('jira.password');
/** @var Config $kanbanBoardUriParams */
$jiraWatchedIssues = $this->config->get('url.jiraWatchedIssues');
$kanbanBoardFilterFields = [
'assignee',
'summary',
'comment',
];
$issueFields = implode(",", $kanbanBoardFilterFields);
$jiraIssueUri = sprintf($jiraWatchedIssues, $filter, $issueFields);
$response = $this->httpClient
->setUri($jiraIssueUri)
->setAuth($user, $password)
->send();
$response = $this->httpClient
->setUri($jiraIssueUri)
->setAuth($user, $password)
->send();
if (!$response->isSuccess()) {
throw new \UnexpectedValueException(sprintf(
"Bad JIRA result for URL:\n%s",
$jiraIssueUri
), $response->getStatusCode());
if (!$response->isSuccess()) {
throw new \UnexpectedValueException(sprintf(
"Bad JIRA result for URL:\n%s",
$jiraIssueUri
), $response->getStatusCode());
}
$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 $this->hydrateWatchedIssues(Decoder::decode($response->getBody(), Json::TYPE_ARRAY), $members);
return unserialize($watchedIssues);
}
/**