<commit_before><?php

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\JsonResponse;
use FOS\RestBundle\Controller\FOSRestController;

class PublicApi20Controller extends FOSRestController
{
	private function prepareResponse(array $entities, Request $request, array $additionalTopLevelProperties = [])
	{
		$response = new JsonResponse();
		$response->headers->set('Access-Control-Allow-Origin', '*');
		$response->headers->set('Content-Type', 'application/json; charset=UTF-8');
		$response->setEncodingOptions(JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
		$response->setPublic();
		$response->setMaxAge($this->container->getParameter('short_cache'));
			
		$dateUpdate = array_reduce($entities, function($carry, $item) {
			if($carry || $item->getDateUpdate() > $carry) return $item->getDateUpdate();
			else return $carry;
		});
		
		$response->setLastModified($dateUpdate);
		if($response->isNotModified($this->getRequest())) {
			return $response;
		}

		$locale = $request->query->get('_locale');
		$translationRepository = $this->getDoctrine()->getManager()->getRepository('Gedmo\Translatable\Entity\Translation');
		
		$content = $additionalTopLevelProperties;

		$content['data'] = array_map(function ($entity) use ($locale, $translationRepository) {
			$data = $entity->serialize();
				
			if(isset($locale))
			{
				$translations = $translationRepository->findTranslations($entity);
				if(isset($translations[$locale])) {
					$translation = $translations[$locale];
					$translation = array_filter($translation, function ($var) { return isset($var); });
					$data['_locale'] = [ $locale => $translation ];
				}
			}
			
			return $data;<commit_msg>fix issue with cached data<commit_after><?php

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\JsonResponse;
use FOS\RestBundle\Controller\FOSRestController;

class PublicApi20Controller extends FOSRestController
{
	private function prepareResponse(array $entities, Request $request, array $additionalTopLevelProperties = [])
	{
		$response = new JsonResponse();
		$response->headers->set('Access-Control-Allow-Origin', '*');
		$response->headers->set('Content-Type', 'application/json; charset=UTF-8');
		$response->setEncodingOptions(JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
		$response->setPublic();
		$response->setMaxAge($this->container->getParameter('short_cache'));
			
		$dateUpdate = array_reduce($entities, function($carry, $item) {
			if(!$carry || ($item->getDateUpdate() > $carry)) return $item->getDateUpdate();
			else return $carry;
		});
		
		$response->setLastModified($dateUpdate);
		if($response->isNotModified($this->getRequest())) {
			return $response;
		}

		$locale = $request->query->get('_locale');
		$translationRepository = $this->getDoctrine()->getManager()->getRepository('Gedmo\Translatable\Entity\Translation');
		
		$content = $additionalTopLevelProperties;

		$content['data'] = array_map(function ($entity) use ($locale, $translationRepository) {
			$data = $entity->serialize();
				
			if(isset($locale))
			{
				$translations = $translationRepository->findTranslations($entity);
				if(isset($translations[$locale])) {
					$translation = $translations[$locale];
					$translation = array_filter($translation, function ($var) { return isset($var); });
					$data['_locale'] = [ $locale => $translation ];
				}
			}
			
			return $data;
{'fraction_non_alphanumeric': 0.15601900739176347, 'fraction_numerical': 0.0015839493136219642, 'mean_word_length': 5.8517179023508135, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '366052', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1098, 'n_words': 173}