Overview
Comment:Use caching for account selector
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 15aa37bcb8634554dda9f439f7a3284964d33a8f
User & Date: bohwaz on 2020-11-16 21:01:23
Other Links: branch diff | manifest | tags
Context
2020-11-16
21:04
Delete the custom image when the colors and the file are reset check-in: 73f43f4d72 user: bohwaz tags: dev
21:01
Use caching for account selector check-in: 15aa37bcb8 user: bohwaz tags: dev
21:01
record the last change to accounting charts, so that it can be used for caching check-in: ccabf2ae96 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Fichiers.php from [48bda0546e] to [7e71959a07].

365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
	 * @param  string $name Nom du fichier avec extension
	 * @param  integer $size Taille du fichier en octets (facultatif)
	 * @return boolean TRUE en cas de succès
	 */
	protected function _serve($path, $type, $name = false, $size = null, bool $public = false)
	{
		if ($public) {
			header(sprintf('Last-Modified: %s GMT', gmdate('D, d M Y H:i:s', $this->datetime)));
			header(sprintf('Etag: %s', $this->hash));
			header('Cache-Control: public');

			$etag = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : null;
			$last_modified = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : null;

			if ($etag === $this->hash && $last_modified <= $this->datetime) {
				header('HTTP/1.1 304 Not Modified', true, 304);
				exit;
			}
		}
		else {
			// Désactiver le cache
			header('Pragma: public');
			header('Expires: -1');
			header('Cache-Control: public, must-revalidate, post-check=0, pre-check=0');
		}







|
<
<
<
<
<
<
<
<
<
<







365
366
367
368
369
370
371
372










373
374
375
376
377
378
379
	 * @param  string $name Nom du fichier avec extension
	 * @param  integer $size Taille du fichier en octets (facultatif)
	 * @return boolean TRUE en cas de succès
	 */
	protected function _serve($path, $type, $name = false, $size = null, bool $public = false)
	{
		if ($public) {
			Utils::HTTPCache($this->hash, $this->datetime);










		}
		else {
			// Désactiver le cache
			header('Pragma: public');
			header('Expires: -1');
			header('Cache-Control: public, must-revalidate, post-check=0, pre-check=0');
		}

Modified src/include/lib/Garradin/Utils.php from [e986fddf0d] to [e5c33a1a87].

824
825
826
827
828
829
830
831

















                case $b: $h = ($r - $g) / $d + 4; break;
            }
            $h /= 6;
        }

        return array($h * 360, $s, $v);
    }
}
























|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
                case $b: $h = ($r - $g) / $d + 4; break;
            }
            $h /= 6;
        }

        return array($h * 360, $s, $v);
    }

    static public function HTTPCache(string $hash, int $expiry): bool
    {
        $etag = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : null;
        $last_modified = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : null;

        if ($etag === $hash && $last_modified <= $expiry) {
            header('HTTP/1.1 304 Not Modified', true, 304);
            exit;
        }

        header(sprintf('Last-Modified: %s GMT', gmdate('D, d M Y H:i:s', $expiry)));
        header(sprintf('Etag: %s', $hash));
        header('Cache-Control: private');

        return false;
    }
}

Modified src/www/admin/acc/charts/accounts/selector.php from [232649b9e9] to [df203fcddd].

7
8
9
10
11
12
13

14
15



16
17



18
19
20
21
22
23
24
use Garradin\Accounting\Years;

require_once __DIR__ . '/../../_inc.php';

header('X-Frame-Options: SAMEORIGIN', true);

$targets = qg('targets');


$chart = null;




if (qg('chart')) {



	$chart = Charts::get((int)qg('chart'));
}
elseif (qg('year')) {
	$year = Years::get((int)qg('year'));

	if ($year) {
		$chart = $year->chart();







>

<
>
>
>

<
>
>
>







7
8
9
10
11
12
13
14
15

16
17
18
19

20
21
22
23
24
25
26
27
28
29
use Garradin\Accounting\Years;

require_once __DIR__ . '/../../_inc.php';

header('X-Frame-Options: SAMEORIGIN', true);

$targets = qg('targets');
$chart = qg('chart');


// Cache the page until the charts have changed
$hash = sha1($targets . $chart);
$expiry = Config::getInstance()->get('last_chart_change') ?: time();


Utils::HTTPCache($hash, $expiry);

if ($chart) {
	$chart = Charts::get((int)qg('chart'));
}
elseif (qg('year')) {
	$year = Years::get((int)qg('year'));

	if ($year) {
		$chart = $year->chart();