Skip to content

Commit

Permalink
Revert all unrelated commits to this project
Browse files Browse the repository at this point in the history
  • Loading branch information
MolloKhan committed Feb 5, 2021
1 parent 2f35e0f commit 63cf640
Show file tree
Hide file tree
Showing 142 changed files with 8,031 additions and 3,691 deletions.
8 changes: 3 additions & 5 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ APP_SECRET=77edcf2d21c9bb9eb67233d29c618543

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://db_user:[email protected]:3306/db_name?serverVersion=5.7"
DATABASE_URL=mysql://root:@127.0.0.1:3306/solid?serverVersion=5.7
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Configure your db driver and server_version in config/packages/doctrine.yaml
DATABASE_URL=mysql://root:@127.0.0.1:3306/blackfire
###< doctrine/doctrine-bundle ###
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
Expand Down
5 changes: 5 additions & 0 deletions _tuts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Hello there!

The files in this directory cannot be modified directly: we use an internal tool
to manage them. If you find an issue with the code, you can open an issue on the
repository. In fact, that would be awesome :).
14 changes: 14 additions & 0 deletions _tuts/command-move-flush-out-of-loop.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/src/Command/UpdateSightingScoresCommand.php b/src/Command/UpdateSightingScoresCommand.php
index 163c167..d279548 100644
--- a/src/Command/UpdateSightingScoresCommand.php
+++ b/src/Command/UpdateSightingScoresCommand.php
@@ -46,8 +46,8 @@ class UpdateSightingScoresCommand extends Command

$score = ceil(min($characterCount / 500, 10));
$sighting->setScore($score);
- $this->entityManager->flush();
}
+ $this->entityManager->flush();
$io->progressFinish();
}
}
12 changes: 12 additions & 0 deletions _tuts/env-homepage-wall-time-assert.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/.blackfire.yaml b/.blackfire.yaml
index 2aeea6b..169cbf4 100644
--- a/.blackfire.yaml
+++ b/.blackfire.yaml
@@ -15,6 +15,7 @@ scenarios: |
expect status_code() == 200
expect css("tbody.js-sightings-list tr").count() > 10
assert metrics.sql.queries.count < 30
+ assert main.wall_time < 100ms

click link("Log In")
name "Log in page"
25 changes: 25 additions & 0 deletions _tuts/env-move-scenario-to-blackfire-yaml.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff --git a/.blackfire.yaml b/.blackfire.yaml
index 8a2bd73..7f465f2 100644
--- a/.blackfire.yaml
+++ b/.blackfire.yaml
@@ -3,3 +3,20 @@
path: "/.*"
assertions:
- "metrics.http.requests.count <= 1"
+
+scenarios: |
+ #!blackfire-player
+
+ scenario
+ name "Basic Visit"
+
+ visit url('/')
+ name "Homepage"
+ expect status_code() == 200
+ expect css("tbody.js-sightings-list tr").count() > 10
+ # won't work until we're using Blackfire environment
+ assert metrics.sql.queries.count < 30
+
+ click link("Log In")
+ name "Log in page"
+ expect status_code() == 200
12 changes: 12 additions & 0 deletions _tuts/env-remove-comment.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/.blackfire.yaml b/.blackfire.yaml
index 7f465f2..2aeea6b 100644
--- a/.blackfire.yaml
+++ b/.blackfire.yaml
@@ -14,7 +14,6 @@ scenarios: |
name "Homepage"
expect status_code() == 200
expect css("tbody.js-sightings-list tr").count() > 10
- # won't work until we're using Blackfire environment
assert metrics.sql.queries.count < 30

click link("Log In")
15 changes: 15 additions & 0 deletions _tuts/env-trying-comparison.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/.blackfire.yaml b/.blackfire.yaml
index 169cbf4..be4ff48 100644
--- a/.blackfire.yaml
+++ b/.blackfire.yaml
@@ -3,6 +3,10 @@
path: "/.*"
assertions:
- "metrics.http.requests.count <= 1"
+ "Pages are not suddenly *much* slower":
+ path: "/.*"
+ assertions:
+ - "percent(main.wall_time) < 30%"

scenarios: |
#!blackfire-player
13 changes: 13 additions & 0 deletions _tuts/env-using-variable.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/.blackfire.yaml b/.blackfire.yaml
index be4ff48..21a6d91 100644
--- a/.blackfire.yaml
+++ b/.blackfire.yaml
@@ -19,7 +19,7 @@ scenarios: |
expect status_code() == 200
expect css("tbody.js-sightings-list tr").count() > 10
assert metrics.sql.queries.count < 30
- assert main.wall_time < 100ms
+ assert main.wall_time < (100ms * var('speed_coefficient', 1))

click link("Log In")
name "Log in page"
35 changes: 35 additions & 0 deletions _tuts/first-profile-make-direct-count-query.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
diff --git a/src/Service/CommentHelper.php b/src/Service/CommentHelper.php
index 7a96a4f..f2bff11 100644
--- a/src/Service/CommentHelper.php
+++ b/src/Service/CommentHelper.php
@@ -3,20 +3,20 @@
namespace App\Service;

use App\Entity\User;
+use App\Repository\CommentRepository;

class CommentHelper
{
- public function countRecentCommentsForUser(User $user): int
+ private $commentRepository;
+
+ public function __construct(CommentRepository $commentRepository)
{
- $comments = $user->getComments();
- $commentCount = 0;
- $recentDate = new \DateTimeImmutable('-3 months');
- foreach ($comments as $comment) {
- if ($comment->getCreatedAt() > $recentDate) {
- $commentCount++;
- }
- }
+ $this->commentRepository = $commentRepository;
+ }

- return $commentCount;
+ public function countRecentCommentsForUser(User $user): int
+ {
+ return $this->commentRepository
+ ->countForUser($user, new \DateTimeImmutable('-3 months'));
}
}
29 changes: 29 additions & 0 deletions _tuts/first-profile-property-caching.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php
index 2cd5e63..7be2947 100644
--- a/src/Twig/AppExtension.php
+++ b/src/Twig/AppExtension.php
@@ -12,6 +12,8 @@ class AppExtension extends AbstractExtension
{
private $commentHelper;

+ private $userStatuses = [];
+
public function __construct(CommentHelper $commentHelper)
{
$this->commentHelper = $commentHelper;
@@ -25,6 +27,15 @@ class AppExtension extends AbstractExtension
}

public function getUserActivityText(User $user): string
+ {
+ if (!isset($this->userStatuses[$user->getId()])) {
+ $this->userStatuses[$user->getId()] = $this->calculateUserActivityText($user);
+ }
+
+ return $this->userStatuses[$user->getId()];
+ }
+
+ private function calculateUserActivityText(User $user): string
{
$commentCount = $this->commentHelper->countRecentCommentsForUser($user);

26 changes: 26 additions & 0 deletions _tuts/first-profile-revert-prop-caching.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php
index 7be2947..4a18185 100644
--- a/src/Twig/AppExtension.php
+++ b/src/Twig/AppExtension.php
@@ -12,8 +12,6 @@ class AppExtension extends AbstractExtension
{
private $commentHelper;

- private $userStatuses = [];
-
public function __construct(CommentHelper $commentHelper)
{
$this->commentHelper = $commentHelper;
@@ -28,11 +26,7 @@ class AppExtension extends AbstractExtension

public function getUserActivityText(User $user): string
{
- if (!isset($this->userStatuses[$user->getId()])) {
- $this->userStatuses[$user->getId()] = $this->calculateUserActivityText($user);
- }
-
- return $this->userStatuses[$user->getId()];
+ return $this->calculateUserActivityText($user);
}

private function calculateUserActivityText(User $user): string
13 changes: 13 additions & 0 deletions _tuts/first-profile-switch-to-prod.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/.env b/.env
index 1f68332..ac88cd0 100644
--- a/.env
+++ b/.env
@@ -14,7 +14,7 @@
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration

###> symfony/framework-bundle ###
-APP_ENV=dev
+APP_ENV=prod
APP_SECRET=77edcf2d21c9bb9eb67233d29c618543
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
#TRUSTED_HOSTS='^localhost|example\.com$'
42 changes: 42 additions & 0 deletions _tuts/first-profile-use-proper-caching.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php
index 4a18185..eb73e33 100644
--- a/src/Twig/AppExtension.php
+++ b/src/Twig/AppExtension.php
@@ -4,6 +4,8 @@ namespace App\Twig;

use App\Entity\User;
use App\Service\CommentHelper;
+use Psr\Cache\CacheItemInterface;
+use Symfony\Contracts\Cache\CacheInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
@@ -11,10 +13,12 @@ use Twig\TwigFunction;
class AppExtension extends AbstractExtension
{
private $commentHelper;
+ private $cache;

- public function __construct(CommentHelper $commentHelper)
+ public function __construct(CommentHelper $commentHelper, CacheInterface $cache)
{
$this->commentHelper = $commentHelper;
+ $this->cache = $cache;
}

public function getFilters(): array
@@ -26,7 +30,13 @@ class AppExtension extends AbstractExtension

public function getUserActivityText(User $user): string
{
- return $this->calculateUserActivityText($user);
+ $key = sprintf('user_activity_text_'.$user->getId());
+
+ return $this->cache->get($key, function(CacheItemInterface $item) use ($user) {
+ $item->expiresAfter(3600);
+
+ return $this->calculateUserActivityText($user);
+ });
}

private function calculateUserActivityText(User $user): string
11 changes: 11 additions & 0 deletions _tuts/metrics-blackfire-yaml-with-1-test.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff --git a/.blackfire.yaml b/.blackfire.yaml
new file mode 100644
index 0000000..8a2bd73
--- /dev/null
+++ b/.blackfire.yaml
@@ -0,0 +1,5 @@
+"tests":
+ "HTTP Requests should be limited to 1 per page":
+ path: "/.*"
+ assertions:
+ - "metrics.http.requests.count <= 1"
13 changes: 13 additions & 0 deletions _tuts/n-1-extra-lazy.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/Entity/BigFootSighting.php b/src/Entity/BigFootSighting.php
index 1e1f5eb..daf6cbf 100644
--- a/src/Entity/BigFootSighting.php
+++ b/src/Entity/BigFootSighting.php
@@ -55,7 +55,7 @@ class BigFootSighting
private $createdAt;

/**
- * @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="bigFootSighting")
+ * @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="bigFootSighting", fetch="EXTRA_LAZY")
* @ORM\OrderBy({"createdAt"="DESC"})
*/
private $comments;
13 changes: 13 additions & 0 deletions _tuts/n-1-revert-join.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/Repository/BigFootSightingRepository.php b/src/Repository/BigFootSightingRepository.php
index 7aa4416..d0a075a 100644
--- a/src/Repository/BigFootSightingRepository.php
+++ b/src/Repository/BigFootSightingRepository.php
@@ -23,8 +23,6 @@ class BigFootSightingRepository extends ServiceEntityRepository
public function findLatestQueryBuilder(int $maxResults): QueryBuilder
{
return $this->createQueryBuilder('big_foot_sighting')
- ->leftJoin('big_foot_sighting.comments', 'comments')
- ->addSelect('comments')
->setMaxResults($maxResults)
->orderBy('big_foot_sighting.createdAt', 'DESC');
}
13 changes: 13 additions & 0 deletions _tuts/n-1-use-join.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/Repository/BigFootSightingRepository.php b/src/Repository/BigFootSightingRepository.php
index d0a075a..7aa4416 100644
--- a/src/Repository/BigFootSightingRepository.php
+++ b/src/Repository/BigFootSightingRepository.php
@@ -23,6 +23,8 @@ class BigFootSightingRepository extends ServiceEntityRepository
public function findLatestQueryBuilder(int $maxResults): QueryBuilder
{
return $this->createQueryBuilder('big_foot_sighting')
+ ->leftJoin('big_foot_sighting.comments', 'comments')
+ ->addSelect('comments')
->setMaxResults($maxResults)
->orderBy('big_foot_sighting.createdAt', 'DESC');
}
14 changes: 14 additions & 0 deletions _tuts/player-add-1-expect.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/scenario.bkf b/scenario.bkf
index d2a095c..68a9636 100644
--- a/scenario.bkf
+++ b/scenario.bkf
@@ -8,6 +8,9 @@ scenario

visit url("/")
name "Homepage"
+ expect status_code() == 200

click link("Log In")
name "Login page"
+ expect status_code() == 200
+
17 changes: 17 additions & 0 deletions _tuts/player-add-1-scenario-2-pages.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/scenario.bkf b/scenario.bkf
index feca60f..d2a095c 100644
--- a/scenario.bkf
+++ b/scenario.bkf
@@ -2,3 +2,12 @@ name "Various scenarios for the site"

# override with --endpoint option
endpoint "https://localhost:8000"
+
+scenario
+ name "Basic Visit"
+
+ visit url("/")
+ name "Homepage"
+
+ click link("Log In")
+ name "Login page"
12 changes: 12 additions & 0 deletions _tuts/player-add-failing-expect.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/scenario.bkf b/scenario.bkf
index 68a9636..5eb1447 100644
--- a/scenario.bkf
+++ b/scenario.bkf
@@ -9,6 +9,7 @@ scenario
visit url("/")
name "Homepage"
expect status_code() == 200
+ expect css("tbody.js-sightings-list tr").count() > 500

click link("Log In")
name "Login page"
10 changes: 10 additions & 0 deletions _tuts/player-bootstrap-scenario-bkf.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
diff --git a/scenario.bkf b/scenario.bkf
new file mode 100644
index 0000000..feca60f
--- /dev/null
+++ b/scenario.bkf
@@ -0,0 +1,4 @@
+name "Various scenarios for the site"
+
+# override with --endpoint option
+endpoint "https://localhost:8000"
13 changes: 13 additions & 0 deletions _tuts/player-example-assert.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/scenario.bkf b/scenario.bkf
index 92be148..8a58fb0 100644
--- a/scenario.bkf
+++ b/scenario.bkf
@@ -10,6 +10,8 @@ scenario
name "Homepage"
expect status_code() == 200
expect css("tbody.js-sightings-list tr").count() > 10
+ # won't work until we're using Blackfire environment
+ assert metrics.sql.queries.count < 30

click link("Log In")
name "Login page"
Loading

0 comments on commit 63cf640

Please sign in to comment.