fix(fediverse): do not cache remote action form + fix typo on post routes for passing post uuid

+ remove unnecessary session->start() directive
This commit is contained in:
Yassine Doghri 2023-09-17 10:07:59 +00:00
parent 3189f12206
commit 4ecb42f7c8
8 changed files with 20 additions and 39 deletions

View File

@ -55,11 +55,11 @@ class Cache extends BaseConfig
* Whether to take the URL query string into consideration when generating
* output cache files. Valid options are:
*
* false = Disabled
* true = Enabled, take all query parameters into account.
* Please be aware that this may result in numerous cache
* files generated for the same page over and over again.
* array('q') = Enabled, but only take into account the specified list
* false = Disabled
* true = Enabled, take all query parameters into account.
* Please be aware that this may result in numerous cache
* files generated for the same page over and over again.
* ['q'] = Enabled, but only take into account the specified list
* of query parameters.
*
* @var boolean|string[]
@ -97,6 +97,7 @@ class Cache extends BaseConfig
* A string of reserved characters that will not be allowed in keys or tags.
* Strings that violate this restriction will cause handlers to throw.
* Default: {}()/\@:
*
* Note: The default set is required for PSR-6 compliance.
*/
public string $reservedCharacters = '{}()/\@:';

View File

@ -6,7 +6,7 @@ use CodeIgniter\Router\RouteCollection;
/**
* @var RouteCollection $routes
/**
*
* --------------------------------------------------------------------
* Placeholder definitions
* --------------------------------------------------------------------
@ -232,7 +232,7 @@ $routes->group('@(:podcastHandle)', static function ($routes): void {
],
'application/ld+json; profile="https://www.w3.org/ns/activitystreams' => [
'namespace' => 'Modules\Fediverse\Controllers',
'controller-method' => 'PostController::index\$2',
'controller-method' => 'PostController::index/$2',
],
],
'filter' => 'allow-cors',

View File

@ -133,7 +133,6 @@ class EpisodeAudioController extends Controller
}
$session = Services::session();
$session->start();
$serviceName = '';
if ($this->request->getGet('_from')) {

View File

@ -176,7 +176,7 @@ class EpisodeController extends BaseController
}
$session = Services::session();
$session->start();
if (service('superglobals')->server('HTTP_REFERER') !== null) {
$session->set('embed_domain', parse_url(service('superglobals')->server('HTTP_REFERER'), PHP_URL_HOST));
}

View File

@ -249,28 +249,17 @@ class PostController extends FediversePostController
$this->registerPodcastWebpageHit($this->podcast->id);
}
$cacheName = implode(
'_',
array_filter(['page', "post#{$this->post->id}", "remote_{$action}", service('request') ->getLocale()]),
);
$data = [
'metatags' => get_remote_actions_metatags($this->post, $action),
'podcast' => $this->podcast,
'actor' => $this->actor,
'post' => $this->post,
'action' => $action,
];
if (! ($cachedView = cache($cacheName))) {
$data = [
'metatags' => get_remote_actions_metatags($this->post, $action),
'podcast' => $this->podcast,
'actor' => $this->actor,
'post' => $this->post,
'action' => $action,
];
helper('form');
helper('form');
return view('post/remote_action', $data, [
'cache' => DECADE,
'cache_name' => $cacheName,
]);
}
return (string) $cachedView;
// NO VIEW CACHING: form has a CSRF token which should change on each request
return view('post/remote_action', $data);
}
}

View File

@ -24,7 +24,6 @@ trait AnalyticsTrait
set_user_session_entry_page();
$session = Services::session();
$session->start();
if (! $session->get('denyListIp')) {
$db = db_connect();

View File

@ -56,7 +56,6 @@ if (! function_exists('set_user_session_deny_list_ip')) {
function set_user_session_deny_list_ip(): void
{
$session = Services::session();
$session->start();
if (! $session->has('denyListIp')) {
$session->set('denyListIp', IpDb::find(client_ip()) !== null);
@ -71,7 +70,6 @@ if (! function_exists('set_user_session_location')) {
function set_user_session_location(): void
{
$session = Services::session();
$session->start();
$location = [
'countryCode' => 'N/A',
@ -112,7 +110,6 @@ if (! function_exists('set_user_session_player')) {
function set_user_session_player(): void
{
$session = Services::session();
$session->start();
if (! $session->has('player')) {
$playerFound = null;
@ -155,7 +152,6 @@ if (! function_exists('set_user_session_browser')) {
function set_user_session_browser(): void
{
$session = Services::session();
$session->start();
if (! $session->has('browser')) {
$browserName = '- Other -';
@ -182,7 +178,6 @@ if (! function_exists('set_user_session_referer')) {
function set_user_session_referer(): void
{
$session = Services::session();
$session->start();
$newreferer = isset($_SERVER['HTTP_REFERER'])
? $_SERVER['HTTP_REFERER']
@ -205,7 +200,6 @@ if (! function_exists('set_user_session_entry_page')) {
function set_user_session_entry_page(): void
{
$session = Services::session();
$session->start();
$entryPage = $_SERVER['REQUEST_URI'];
if (! $session->has('entryPage')) {
@ -245,7 +239,6 @@ if (! function_exists('podcast_hit')) {
?int $subscriptionId,
): void {
$session = Services::session();
$session->start();
$clientIp = client_ip();

View File

@ -50,7 +50,7 @@ class PostController extends Controller
public function _remap(string $method, string ...$params): mixed
{
if (count($params) === 0) {
if ($params === []) {
throw PageNotFoundException::forPageNotFound();
}