Commit a4b92d35 authored by Emma's avatar Emma 🏳🌈

preliminary HTTP cache support

parent 16b6499c
Pipeline #60458655 passed with stage
in 1 minute and 39 seconds
......@@ -4,20 +4,57 @@
# priority over values declared here. #
################################################################################
### Basic settings
SITE_NAME=Postmill
NO_REPLY_ADDRESS="no-reply@example.com"
###> doctrine/doctrine-bundle ###
# Copy this line to .env.local and change it according to your database setup.
# Don't even think about trying another kind of database, it won't work.
DATABASE_URL=pgsql://db_user:db_password@localhost:5432/db_name?serverVersion=9.6
###< doctrine/doctrine-bundle ###
###> symfony/framework-bundle ###
# Set to 'prod' if your Postmill will be available to the public internet!
APP_ENV=dev
# Change this to something random, secret, and long
APP_SECRET="change this in prod or die"
###< symfony/framework-bundle ###
### HTTP settings
# Enable built-in HTTP cache
# This can boost performance significantly for pages where caching is enabled.
# Disable this if using an external caching proxy.
USE_HTTP_CACHE=1
###> symfony/framework-bundle ###
# If Postmill is being proxied (e.g. with Varnish, or services like CloudFlare,
# Heroku, etc.), set this to the comma-separated list of IP addresses that are
# valid proxies. Failure to configure this properly can result in false
# positives for IP bans.
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
# Valid host names for your site
# (this is better done by setting up vhosts properly in your web server)
#TRUSTED_HOSTS=localhost,example.com
###< symfony/framework-bundle ###
### Locales
# Set this to your desired default language. Note that the browser's language
# settings may override this.
APP_LOCALE=en
APP_ENABLE_WEBHOOKS=0
# A list of IP addresses (with optional CIDR mask) exempt from IP-based rate
# limiting. Leave blank to disable.
#RATELIMIT_WHITELIST=127.0.0.1,192.168.2.0/24
# Available languages on your site (you probably don't need to change this)
AVAILABLE_LOCALES=de,el,en,eo,es,fi,fr,nb,nl,pt_BR
# Configuration that disables IP-based rate limiting.
#RATELIMIT_WHITELIST=0.0.0.0/0,::/0
# No whitelisting by default
RATELIMIT_WHITELIST=
### File uploads
# Configure how uploads (i.e. downloaded submission images/thumbnails) are
# handled. By default, they're stored in Postmill's public/ directory, and are
......@@ -36,21 +73,12 @@ UPLOAD_HOST=
#UPLOAD_ROOT=https://minio.example/bucket-name
#UPLOAD_HOST=minio.example
APP_FONTS=%kernel.project_dir%/assets/fonts.json
APP_THEMES=%kernel.project_dir%/assets/themes.json
###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET="change this in prod or die"
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
#TRUSTED_HOSTS=localhost,example.com
###< symfony/framework-bundle ###
### Mail
###> doctrine/doctrine-bundle ###
# Copy this line to .env.local and change it according to your database setup.
# Don't even think about trying another kind of database, it won't work.
DATABASE_URL=pgsql://db_user:db_password@localhost:5432/db_name?serverVersion=9.6
###< doctrine/doctrine-bundle ###
# The email address to appear in the From header. Make this empty to disable
# password resetting.
NO_REPLY_ADDRESS="no-reply@example.com"
###> symfony/swiftmailer-bundle ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
......@@ -59,4 +87,28 @@ DATABASE_URL=pgsql://db_user:db_password@localhost:5432/db_name?serverVersion=9.
MAILER_URL=null://localhost
###< symfony/swiftmailer-bundle ###
AVAILABLE_LOCALES=de,el,en,eo,es,fi,fr,nb,nl,pt_BR
### Rate limiting
# A list of IP addresses (with optional CIDR mask) exempt from IP-based rate
# limiting. Leave blank to disable.
#RATELIMIT_WHITELIST=127.0.0.1,192.168.2.0/24
# Configuration that disables IP-based rate limiting.
#RATELIMIT_WHITELIST=0.0.0.0/0,::/0
# No whitelisting by default
RATELIMIT_WHITELIST=
### Experimental features
# Enable experimental webhook functionality
# See https://gitlab.com/postmill/Postmill/wikis/webhooks
APP_ENABLE_WEBHOOKS=0
### Misc config files
APP_FONTS=%kernel.project_dir%/assets/fonts.json
APP_THEMES=%kernel.project_dir%/assets/themes.json
KERNEL_CLASS='App\Kernel'
USE_HTTP_CACHE=0
APP_SECRET=33a8a493d8fffeab937480b451ebb289
APP_ENABLE_WEBHOOKS=1
This diff is collapsed.
......@@ -24,4 +24,5 @@ return [
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
Nelmio\SecurityBundle\NelmioSecurityBundle::class => ['all' => true],
FOS\HttpCacheBundle\FOSHttpCacheBundle::class => ['all' => true],
];
fos_http_cache:
cache_control:
rules:
-
match:
path: ^
headers:
vary: [Accept-Encoding, Accept-Language, Cookie]
......@@ -26,6 +26,7 @@ security:
logout:
csrf_parameter: token
csrf_token_generator: security.csrf.token_manager
delete_cookies: [PHPSESSID]
path: log_out
remember_me:
......
......@@ -27,6 +27,11 @@ if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false
}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
if ($_SERVER['USE_HTTP_CACHE']) {
$kernel = $kernel->getHttpCache();
}
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
......
<?php
namespace App;
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
final class CacheKernel extends HttpCache {
}
......@@ -6,12 +6,15 @@ use App\Entity\Submission;
use App\Repository\ForumRepository;
use App\Repository\SubmissionRepository;
use App\Repository\UserRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Actions that list submissions across many forums.
*
* @Cache(smaxage="10 seconds")
*/
final class FrontController extends AbstractController {
/**
......
......@@ -14,6 +14,7 @@ use App\Form\Model\SubmissionData;
use App\Form\SubmissionType;
use App\Utils\Slugger;
use Doctrine\ORM\EntityManager;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
......@@ -30,6 +31,8 @@ final class SubmissionController extends AbstractController {
/**
* Show a submission's comment page.
*
* @Cache(smaxage="10 seconds")
*
* @param Forum $forum
* @param Submission $submission
*
......
......@@ -3,17 +3,26 @@
namespace App;
use App\DependencyInjection\Compiler\VersionPass;
use FOS\HttpCache\SymfonyCache\HttpCacheAware;
use FOS\HttpCache\SymfonyCache\HttpCacheProvider;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
class Kernel extends BaseKernel {
class Kernel extends BaseKernel implements HttpCacheProvider {
use HttpCacheAware;
use MicroKernelTrait;
const CONFIG_EXTS = '.{php,xml,yaml,yml}';
public function __construct(...$args) {
parent::__construct(...$args);
$this->setHttpCache(new CacheKernel($this));
}
public function getCacheDir() {
return $this->getProjectDir().'/var/cache/'.$this->environment;
}
......
......@@ -2,6 +2,9 @@
"aws/aws-sdk-php": {
"version": "3.92.5"
},
"clue/stream-filter": {
"version": "v1.4.1"
},
"composer/ca-bundle": {
"version": "1.1.0"
},
......@@ -131,6 +134,12 @@
"ref": "9d60c231a92e69c68b89897813ec4931d0697b1f"
}
},
"friendsofsymfony/http-cache": {
"version": "2.6.0"
},
"friendsofsymfony/http-cache-bundle": {
"version": "2.6.1"
},
"friendsofsymfony/jsrouting-bundle": {
"version": "2.0",
"recipe": {
......@@ -212,6 +221,27 @@
"php-cs-fixer/diff": {
"version": "v1.2.0"
},
"php-http/client-common": {
"version": "1.9.1"
},
"php-http/discovery": {
"version": "1.6.1"
},
"php-http/guzzle6-adapter": {
"version": "v1.1.1"
},
"php-http/httplug": {
"version": "v1.1.0"
},
"php-http/message": {
"version": "1.7.2"
},
"php-http/message-factory": {
"version": "v1.0.2"
},
"php-http/promise": {
"version": "v1.0.0"
},
"phpdocumentor/reflection-common": {
"version": "1.0.1"
},
......
......@@ -28,16 +28,18 @@
<body class="{{ app.user ? 'user-logged-in' : 'user-anonymous' }} {{ (app.user.nightMode ?? false) ? 'night-mode' }}">
{% block site_alerts %}
<div class="site-alerts">
{%- for type, notices in app.flashes -%}
{%- for notice in notices -%}
<div class="alert alert--{{ type }} site-alerts__alert" role="alert">
<p class="no-margin site-alerts__text">{{ notice|trans }}</p>
<button class="site-alerts__dismiss unbuttonize fg-inherit no-underline"
aria-label="{{ 'action.dismiss'|trans }}"
type="button">&times;</button>
</div>
{%- if app.request.previousSession -%}
{%- for type, notices in app.flashes -%}
{%- for notice in notices -%}
<div class="alert alert--{{ type }} site-alerts__alert" role="alert">
<p class="no-margin site-alerts__text">{{ notice|trans }}</p>
<button class="site-alerts__dismiss unbuttonize fg-inherit no-underline"
aria-label="{{ 'action.dismiss'|trans }}"
type="button">&times;</button>
</div>
{%- endfor -%}
{%- endfor -%}
{%- endfor -%}
{%- endif -%}
</div>
{% endblock site_alerts %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment