Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

burst cache #1615

Merged
merged 8 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/content/frameworks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ type:
type: text
summary:
type: richtext
upcoming_deal_summary:
type: richtext
description:
type: richtext
updates:
Expand Down
4 changes: 3 additions & 1 deletion config/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ frameworks_list:

frameworks_upcoming_deals:
path: /agreements/upcoming
controller: App\Controller\FrameworksController::upcomingDeals
controller: App\Controller\FrameworksController::upcomingDealsSearch
requirements:
page: '\d+'

frameworks_list_by_category:
path: /agreements/category/{category}/{page}/{query}
Expand Down
1 change: 1 addition & 0 deletions src/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private function filterFrameworkParams(array $params)
case 'category':
case 'regulation':
case 'regulation_type':
case 'terms':
if (!is_array($param)) {
$filtered[$name] = filter_var($param, FILTER_SANITIZE_STRING);
} else {
Expand Down
108 changes: 70 additions & 38 deletions src/Controller/FrameworksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ public function list(Request $request, int $page = 1)
return $this->redirectToRoute('frameworks_list', $redirectForCatOrPillar);
}

// Get search query
// strip special characters and tags from search query
$orginalSearch = str_replace('/', '', strip_tags(html_entity_decode($request->query->get('keyword'))));
$query = preg_replace("/[^a-zA-Z0-9\s]/", "", $orginalSearch);
$query = $this->sanitizeSearchQuery($request->query->get('keyword'));
$page = filter_var($page, FILTER_SANITIZE_NUMBER_INT);

$this->searchApi->setCacheKey($request->getRequestUri());
Expand Down Expand Up @@ -208,61 +205,96 @@ public function list(Request $request, int $page = 1)
return $this->render('frameworks/list.html.twig', $data);
}

/**
* List upcoming deals
*
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Strata\Frontend\Exception\ContentFieldException
* @throws \Strata\Frontend\Exception\ContentFieldNotSetException
* @throws \Strata\Frontend\Exception\ContentTypeNotSetException
* @throws \Strata\Frontend\Exception\FailedRequestException
* @throws \Strata\Frontend\Exception\PermissionException
*/
public function upcomingDeals(Request $request)
public function upcomingDealsSearch(Request $request)
{
$this->api->setContentType('upcoming_deals');
$this->api->setCacheKey($request->getRequestUri());
$query = $this->sanitizeSearchQuery($request->query->get('keyword'));
$page = 1;

$this->searchApi->setCacheKey($request->getRequestUri());
$this->searchApi->getContentType()->setApiEndpoint('frameworks');

$limit = $request->query->has('limit') ? (int) filter_var($request->query->get('limit'), FILTER_SANITIZE_NUMBER_INT) : 110;

$checkedTypeArray = $this->getCheckedTypeArray($request);

$options = [
"keyword" => $query,
"checkedStatus" => ["Upcoming", "Live"],
"checkedType" => $checkedTypeArray,
];

// @todo At present need to pass fake ID since API method is intended to return one item with an ID, review this
try {
$results = $this->api->getOne(0);
} catch (NotFoundException $e) {
$results = $this->searchApi->list($page, [
'keyword' => $options['keyword'],
'status' => $options['checkedStatus'],
'limit' => $limit,
'regulation_type' => $options["checkedType"],
'terms' => ["DPS", "Standard"],
]);
} catch (NotFoundException | PaginationException $e) {
throw new NotFoundHttpException('Page not found', $e);
}

// request to upcoming deals information api for titles and description
$upcomingDealsUrl = getenv('APP_API_BASE_URL') . 'ccs/v1/upcoming-deals-page/0';
$upcomingDealsContent = $this->getUpcomingDealsInfo();

$client = HttpClient::create();
$response = $client->request(
'GET',
$upcomingDealsUrl,
);
$cscMessage = ControllerHelper::getCSCMessage();

$upcomingDealsContent = null;
$statuses = (array) $request->query->get('statuses', ['all']);
$checkedTypes = (array) $request->query->get('type', ['allType']);

$cscMessage = ControllerHelper::getCSCMessage();
if (count($statuses) === 5 || in_array('all', $statuses)) {
$statuses = ['all'];
}

if ($response->getStatusCode() == 200) {
$upcomingDealsContent = json_decode($response->getContent());
if (!$checkedTypes || count($checkedTypes) === 5 || in_array('allType', $checkedTypes)) {
$checkedTypes = ["allType"];
}

$data = [
'tpp_feature_toggle' => getenv('TPP_feature_toggle'),
'awarded_pipeline' => $results->getContent()->get('awarded_pipeline'),
'underway_pipeline' => $results->getContent()->get('underway_pipeline'),
'dynamic_purchasing_systems' => $results->getContent()->get('dynamic_purchasing_systems'),
'planned_pipeline' => $results->getContent()->get('planned_pipeline'),
'future_pipeline' => $results->getContent()->get('future_pipeline'),
'statuses' => $statuses,
'filters' => $options,
'results' => $results,
'type' => $checkedTypes,
'upcoming_deals_content' => $upcomingDealsContent,
'cscMessage' => $cscMessage,
];

return $this->render('frameworks/upcoming-list.html.twig', $data);
}

private function sanitizeSearchQuery($keyword)
{
$originalSearch = str_replace('/', '', strip_tags(html_entity_decode($keyword)));
return preg_replace("/[^a-zA-Z0-9\s]/", "", $originalSearch);
}

private function getCheckedTypeArray(Request $request)
{
$checkedTypeArray = ControllerHelper::getArrayFromStringForParam($request, "type");

return (in_array("allType", $checkedTypeArray) || count($checkedTypeArray) === 5)
? []
: $checkedTypeArray;
}

private function getUpcomingDealsInfo()
{
$url = getenv('APP_API_BASE_URL') . 'ccs/v1/upcoming-deals-page/0';

$client = HttpClient::create();
$response = $client->request(
'GET',
$url,
);

if ($response->getStatusCode() == 200) {
$upcomingDealsContent = json_decode($response->getContent());
}

return $upcomingDealsContent;
}

/**
* Show one framework
*
Expand Down
4 changes: 2 additions & 2 deletions templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
{% block pageMetaTags %}{{ (page is defined)? page.head.getAllMetaHtml()|raw : '' }}{% endblock %}

{% if app.environment == "prod" %}
<link rel="stylesheet" href="/assets/styles/styles.min.css?v=1.65">
<link rel="stylesheet" href="/assets/styles/styles.min.css?v=1.66">
{% else %}
{# To debug CSS in other environments (not live), change the below to
# styles.css instead of styles.min.css
#}
<link rel="stylesheet" href="/assets/styles/styles.min.css?v=1.65">
<link rel="stylesheet" href="/assets/styles/styles.min.css?v=1.66">
{% endif %}

{# Browser icon #}
Expand Down
Loading