Browse Source

Optimize page load

imwald
Nuša Pukšič 10 months ago
parent
commit
56e4905635
  1. 9
      .env
  2. 6
      composer.json
  3. 312
      composer.lock
  4. 16
      src/Controller/DefaultController.php
  5. 12
      src/Twig/Components/Molecules/UserFromNpub.php
  6. 3
      symfony.lock

9
.env

@ -48,3 +48,12 @@ ELASTICSEARCH_PORT=9200
ELASTICSEARCH_USERNAME=elastic ELASTICSEARCH_USERNAME=elastic
ELASTICSEARCH_PASSWORD=your_password ELASTICSEARCH_PASSWORD=your_password
###< elastic ### ###< elastic ###
###> redis ###
REDIS_HOST=localhost
REDIS_PASSWORD=r_password
###< redis ###
###> LNBits ###
LNBITS_URL=https://legend.lnbits.com
LNBITS_API_KEY=<your-lnbits-admin-key>
###< LNBits ###

6
composer.json

@ -10,10 +10,13 @@
"ext-ctype": "*", "ext-ctype": "*",
"ext-iconv": "*", "ext-iconv": "*",
"ext-openssl": "*", "ext-openssl": "*",
"ext-redis": "*",
"doctrine/dbal": "^4.2", "doctrine/dbal": "^4.2",
"doctrine/doctrine-bundle": "^2.13", "doctrine/doctrine-bundle": "^2.13",
"doctrine/doctrine-migrations-bundle": "^3.3", "doctrine/doctrine-migrations-bundle": "^3.3",
"doctrine/orm": "^3.3", "doctrine/orm": "^3.3",
"endroid/qr-code": "^6.0",
"endroid/qr-code-bundle": "^6.0",
"friendsofsymfony/elastica-bundle": "^6.5", "friendsofsymfony/elastica-bundle": "^6.5",
"league/commonmark": "^2.6", "league/commonmark": "^2.6",
"league/html-to-markdown": "*", "league/html-to-markdown": "*",
@ -51,7 +54,8 @@
"allow-plugins": { "allow-plugins": {
"php-http/discovery": true, "php-http/discovery": true,
"symfony/flex": true, "symfony/flex": true,
"symfony/runtime": true "symfony/runtime": true,
"endroid/installer": true
}, },
"sort-packages": true "sort-packages": true
}, },

312
composer.lock generated

@ -4,8 +4,62 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "5cfb4f5535c24bf4cbec6db7c20c469e", "content-hash": "8df0c7139f6ed328ea1abb8d715e68db",
"packages": [ "packages": [
{
"name": "bacon/bacon-qr-code",
"version": "v3.0.1",
"source": {
"type": "git",
"url": "https://github.com/Bacon/BaconQrCode.git",
"reference": "f9cc1f52b5a463062251d666761178dbdb6b544f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Bacon/BaconQrCode/zipball/f9cc1f52b5a463062251d666761178dbdb6b544f",
"reference": "f9cc1f52b5a463062251d666761178dbdb6b544f",
"shasum": ""
},
"require": {
"dasprid/enum": "^1.0.3",
"ext-iconv": "*",
"php": "^8.1"
},
"require-dev": {
"phly/keep-a-changelog": "^2.12",
"phpunit/phpunit": "^10.5.11 || 11.0.4",
"spatie/phpunit-snapshot-assertions": "^5.1.5",
"squizlabs/php_codesniffer": "^3.9"
},
"suggest": {
"ext-imagick": "to generate QR code images"
},
"type": "library",
"autoload": {
"psr-4": {
"BaconQrCode\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-2-Clause"
],
"authors": [
{
"name": "Ben Scholzen 'DASPRiD'",
"email": "mail@dasprids.de",
"homepage": "https://dasprids.de/",
"role": "Developer"
}
],
"description": "BaconQrCode is a QR code generator for PHP.",
"homepage": "https://github.com/Bacon/BaconQrCode",
"support": {
"issues": "https://github.com/Bacon/BaconQrCode/issues",
"source": "https://github.com/Bacon/BaconQrCode/tree/v3.0.1"
},
"time": "2024-10-01T13:55:55+00:00"
},
{ {
"name": "bitwasp/bech32", "name": "bitwasp/bech32",
"version": "v0.0.1", "version": "v0.0.1",
@ -133,6 +187,56 @@
], ],
"time": "2024-09-19T14:15:21+00:00" "time": "2024-09-19T14:15:21+00:00"
}, },
{
"name": "dasprid/enum",
"version": "1.0.6",
"source": {
"type": "git",
"url": "https://github.com/DASPRiD/Enum.git",
"reference": "8dfd07c6d2cf31c8da90c53b83c026c7696dda90"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/DASPRiD/Enum/zipball/8dfd07c6d2cf31c8da90c53b83c026c7696dda90",
"reference": "8dfd07c6d2cf31c8da90c53b83c026c7696dda90",
"shasum": ""
},
"require": {
"php": ">=7.1 <9.0"
},
"require-dev": {
"phpunit/phpunit": "^7 || ^8 || ^9 || ^10 || ^11",
"squizlabs/php_codesniffer": "*"
},
"type": "library",
"autoload": {
"psr-4": {
"DASPRiD\\Enum\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-2-Clause"
],
"authors": [
{
"name": "Ben Scholzen 'DASPRiD'",
"email": "mail@dasprids.de",
"homepage": "https://dasprids.de/",
"role": "Developer"
}
],
"description": "PHP 7.1 enum implementation",
"keywords": [
"enum",
"map"
],
"support": {
"issues": "https://github.com/DASPRiD/Enum/issues",
"source": "https://github.com/DASPRiD/Enum/tree/1.0.6"
},
"time": "2024-08-09T14:30:48+00:00"
},
{ {
"name": "dflydev/dot-access-data", "name": "dflydev/dot-access-data",
"version": "v3.0.3", "version": "v3.0.3",
@ -1484,6 +1588,209 @@
}, },
"time": "2023-04-21T15:31:12+00:00" "time": "2023-04-21T15:31:12+00:00"
}, },
{
"name": "endroid/installer",
"version": "1.5.0",
"source": {
"type": "git",
"url": "https://github.com/endroid/installer.git",
"reference": "39109e825057b2e7436123d5ad5dc8c2467a4cf6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/endroid/installer/zipball/39109e825057b2e7436123d5ad5dc8c2467a4cf6",
"reference": "39109e825057b2e7436123d5ad5dc8c2467a4cf6",
"shasum": ""
},
"require": {
"composer-plugin-api": "^2.0",
"php": "^8.2"
},
"require-dev": {
"composer/composer": "^2.0",
"endroid/quality": "dev-main"
},
"suggest": {
"roave/security-advisories": "Avoids installation of package versions with vulnerabilities"
},
"type": "composer-plugin",
"extra": {
"class": "Endroid\\Installer\\Installer",
"branch-alias": {
"dev-main": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"Endroid\\Installer\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jeroen van den Enden",
"email": "info@endroid.nl"
}
],
"description": "Composer plugin for installing configuration files",
"support": {
"issues": "https://github.com/endroid/installer/issues",
"source": "https://github.com/endroid/installer/tree/1.5.0"
},
"funding": [
{
"url": "https://github.com/endroid",
"type": "github"
}
],
"time": "2024-10-20T18:31:36+00:00"
},
{
"name": "endroid/qr-code",
"version": "6.0.6",
"source": {
"type": "git",
"url": "https://github.com/endroid/qr-code.git",
"reference": "11e6a94458dab8dd18736c11892130ec788b5028"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/endroid/qr-code/zipball/11e6a94458dab8dd18736c11892130ec788b5028",
"reference": "11e6a94458dab8dd18736c11892130ec788b5028",
"shasum": ""
},
"require": {
"bacon/bacon-qr-code": "^3.0",
"php": "^8.2"
},
"require-dev": {
"endroid/quality": "dev-main",
"ext-gd": "*",
"khanamiryan/qrcode-detector-decoder": "^2.0.2",
"setasign/fpdf": "^1.8.2"
},
"suggest": {
"ext-gd": "Enables you to write PNG images",
"khanamiryan/qrcode-detector-decoder": "Enables you to use the image validator",
"roave/security-advisories": "Makes sure package versions with known security issues are not installed",
"setasign/fpdf": "Enables you to use the PDF writer"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "6.x-dev"
}
},
"autoload": {
"psr-4": {
"Endroid\\QrCode\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jeroen van den Enden",
"email": "info@endroid.nl"
}
],
"description": "Endroid QR Code",
"homepage": "https://github.com/endroid/qr-code",
"keywords": [
"code",
"endroid",
"php",
"qr",
"qrcode"
],
"support": {
"issues": "https://github.com/endroid/qr-code/issues",
"source": "https://github.com/endroid/qr-code/tree/6.0.6"
},
"funding": [
{
"url": "https://github.com/endroid",
"type": "github"
}
],
"time": "2025-03-14T23:29:08+00:00"
},
{
"name": "endroid/qr-code-bundle",
"version": "6.0.0",
"source": {
"type": "git",
"url": "https://github.com/endroid/qr-code-bundle.git",
"reference": "b1e6972cf7ec154f646f0b0d9d12ca901bc0b9d1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/endroid/qr-code-bundle/zipball/b1e6972cf7ec154f646f0b0d9d12ca901bc0b9d1",
"reference": "b1e6972cf7ec154f646f0b0d9d12ca901bc0b9d1",
"shasum": ""
},
"require": {
"endroid/installer": "^1.2.2",
"endroid/qr-code": "^6.0.1",
"php": "^8.2",
"symfony/framework-bundle": "^5.4||^6.4||^7.0",
"symfony/twig-bundle": "^5.4||^6.4||^7.0",
"symfony/yaml": "^5.4||^6.4||^7.0"
},
"require-dev": {
"endroid/quality": "dev-main"
},
"suggest": {
"roave/security-advisories": "Avoids installation of package versions with vulnerabilities"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-main": "6.x-dev"
}
},
"autoload": {
"psr-4": {
"Endroid\\QrCodeBundle\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jeroen van den Enden",
"email": "info@endroid.nl"
}
],
"description": "Endroid QR Code Bundle",
"homepage": "https://github.com/endroid/qr-code-bundle",
"keywords": [
"bundle",
"code",
"endroid",
"php",
"qr",
"symfony"
],
"support": {
"issues": "https://github.com/endroid/qr-code-bundle/issues",
"source": "https://github.com/endroid/qr-code-bundle/tree/6.0.0"
},
"funding": [
{
"url": "https://github.com/endroid",
"type": "github"
}
],
"time": "2024-10-21T23:18:20+00:00"
},
{ {
"name": "ezimuel/guzzlestreams", "name": "ezimuel/guzzlestreams",
"version": "3.1.0", "version": "3.1.0",
@ -11513,7 +11820,8 @@
"php": ">=8.3.13", "php": ">=8.3.13",
"ext-ctype": "*", "ext-ctype": "*",
"ext-iconv": "*", "ext-iconv": "*",
"ext-openssl": "*" "ext-openssl": "*",
"ext-redis": "*"
}, },
"platform-dev": {}, "platform-dev": {},
"plugin-api-version": "2.6.0" "plugin-api-version": "2.6.0"

16
src/Controller/DefaultController.php

@ -6,7 +6,6 @@ namespace App\Controller;
use App\Entity\Article; use App\Entity\Article;
use App\Enum\IndexStatusEnum; use App\Enum\IndexStatusEnum;
use App\Service\NostrClient;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use FOS\ElasticaBundle\Finder\FinderInterface; use FOS\ElasticaBundle\Finder\FinderInterface;
use Psr\Cache\InvalidArgumentException; use Psr\Cache\InvalidArgumentException;
@ -20,8 +19,7 @@ class DefaultController extends AbstractController
{ {
public function __construct( public function __construct(
private readonly FinderInterface $esFinder, private readonly FinderInterface $esFinder,
private readonly EntityManagerInterface $entityManager, private readonly EntityManagerInterface $entityManager)
private readonly NostrClient $nostrClient)
{ {
} }
@ -31,7 +29,7 @@ class DefaultController extends AbstractController
#[Route('/', name: 'default')] #[Route('/', name: 'default')]
public function index(): Response public function index(): Response
{ {
$list = $this->entityManager->getRepository(Article::class)->findBy(['indexStatus' => IndexStatusEnum::INDEXED], ['createdAt' => 'DESC'], 5); $list = $this->entityManager->getRepository(Article::class)->findBy(['indexStatus' => IndexStatusEnum::INDEXED], ['createdAt' => 'DESC'], 10);
// deduplicate by slugs // deduplicate by slugs
$deduplicated = []; $deduplicated = [];
@ -41,14 +39,10 @@ class DefaultController extends AbstractController
} }
} }
$npubs = array_map(function($obj) {
return $obj->getPubkey();
}, $list);
// $this->nostrClient->getMetadata(array_unique($npubs));
return $this->render('home.html.twig', [ return $this->render('home.html.twig', [
'list' => array_values($deduplicated) 'list' => array_values(array_filter($deduplicated, function($item) {
return !empty($item->getImage());
}))
]); ]);
} }

12
src/Twig/Components/Molecules/UserFromNpub.php

@ -4,6 +4,7 @@ namespace App\Twig\Components\Molecules;
use App\Service\NostrClient; use App\Service\NostrClient;
use Psr\Cache\InvalidArgumentException; use Psr\Cache\InvalidArgumentException;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
#[AsTwigComponent] #[AsTwigComponent]
@ -12,17 +13,24 @@ final class UserFromNpub
public string $npub; public string $npub;
public ?array $user = null; public ?array $user = null;
public function __construct(private readonly NostrClient $nostrClient) public function __construct(private readonly NostrClient $nostrClient, private readonly CacheInterface $redisCache)
{ {
} }
public function mount(string $npub): void public function mount(string $npub): void
{ {
$this->npub = $npub; $this->npub = $npub;
try {
$this->user = $this->redisCache->get('user_' . $npub, function () use ($npub) {
try { try {
$meta = $this->nostrClient->getNpubMetadata($npub); $meta = $this->nostrClient->getNpubMetadata($npub);
$this->user = (array) json_decode($meta->content); return (array) json_decode($meta->content);
} catch (InvalidArgumentException|\Exception) { } catch (InvalidArgumentException|\Exception) {
return null;
}
});
} catch (InvalidArgumentException $e) {
$this->user = null; $this->user = null;
} }
} }

3
symfony.lock

@ -26,6 +26,9 @@
"./migrations/.gitignore" "./migrations/.gitignore"
] ]
}, },
"endroid/qr-code-bundle": {
"version": "6.0.0"
},
"friendsofsymfony/elastica-bundle": { "friendsofsymfony/elastica-bundle": {
"version": "6.5", "version": "6.5",
"recipe": { "recipe": {

Loading…
Cancel
Save