Skip to content

Commit

Permalink
Hotfix: Adding indexes for project/user
Browse files Browse the repository at this point in the history
  • Loading branch information
dmetzner committed Feb 17, 2023
1 parent f025a76 commit 33eeaab
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 19 deletions.
45 changes: 45 additions & 0 deletions migrations/2023/Version20230217092939.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230217092939 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE INDEX upload_token_idx ON fos_user (upload_token)');
$this->addSql('CREATE INDEX confirmation_token_isx ON fos_user (confirmation_token)');
$this->addSql('CREATE INDEX username_canonical_idx ON fos_user (username_canonical)');
$this->addSql('CREATE INDEX email_canonical_idx ON fos_user (email_canonical)');
$this->addSql('CREATE INDEX scratch_user_id_idx ON fos_user (scratch_user_id)');
$this->addSql('CREATE INDEX google_id_idx ON fos_user (google_id)');
$this->addSql('CREATE INDEX facebook_id_idx ON fos_user (google_id)');
$this->addSql('CREATE INDEX apple_id_idx ON fos_user (google_id)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX upload_token_idx ON fos_user');
$this->addSql('DROP INDEX confirmation_token_isx ON fos_user');
$this->addSql('DROP INDEX username_canonical_idx ON fos_user');
$this->addSql('DROP INDEX email_canonical_idx ON fos_user');
$this->addSql('DROP INDEX scratch_user_id_idx ON fos_user');
$this->addSql('DROP INDEX google_id_idx ON fos_user');
$this->addSql('DROP INDEX facebook_id_idx ON fos_user');
$this->addSql('DROP INDEX apple_id_idx ON fos_user');
}
}
59 changes: 59 additions & 0 deletions migrations/2023/Version20230217100800.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230217100800 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE INDEX internal_title_idx ON extension (internal_title)');
$this->addSql('ALTER TABLE program DROP FOREIGN KEY FK_92ED7784A76ED395');
$this->addSql('CREATE INDEX uploaded_at_idx ON program (uploaded_at)');
$this->addSql('CREATE INDEX views_idx ON program (views)');
$this->addSql('CREATE INDEX downloads_idx ON program (downloads)');
$this->addSql('CREATE INDEX name_idx ON program (name)');
$this->addSql('CREATE INDEX language_version_idx ON program (language_version)');
$this->addSql('CREATE INDEX visible_idx ON program (visible)');
$this->addSql('CREATE INDEX private_idx ON program (private)');
$this->addSql('CREATE INDEX debug_build_idx ON program (debug_build)');
$this->addSql('CREATE INDEX flavor_idx ON program (flavor)');
$this->addSql('DROP INDEX idx_92ed7784a76ed395 ON program');
$this->addSql('CREATE INDEX user_idx ON program (user_id)');
$this->addSql('ALTER TABLE program ADD CONSTRAINT FK_92ED7784A76ED395 FOREIGN KEY (user_id) REFERENCES fos_user (id)');
$this->addSql('CREATE INDEX internal_title_idx ON tags (internal_title)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX uploaded_at_idx ON program');
$this->addSql('DROP INDEX views_idx ON program');
$this->addSql('DROP INDEX downloads_idx ON program');
$this->addSql('DROP INDEX name_idx ON program');
$this->addSql('DROP INDEX language_version_idx ON program');
$this->addSql('DROP INDEX visible_idx ON program');
$this->addSql('DROP INDEX private_idx ON program');
$this->addSql('DROP INDEX debug_build_idx ON program');
$this->addSql('DROP INDEX flavor_idx ON program');
$this->addSql('ALTER TABLE program DROP FOREIGN KEY FK_92ED7784A76ED395');
$this->addSql('DROP INDEX user_idx ON program');
$this->addSql('CREATE INDEX IDX_92ED7784A76ED395 ON program (user_id)');
$this->addSql('ALTER TABLE program ADD CONSTRAINT FK_92ED7784A76ED395 FOREIGN KEY (user_id) REFERENCES fos_user (id)');
$this->addSql('DROP INDEX internal_title_idx ON tags');
$this->addSql('DROP INDEX internal_title_idx ON extension');
}
}
6 changes: 2 additions & 4 deletions src/Api_deprecated/OAuth/OAuthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ public function checkEMailAvailable(Request $request): JsonResponse
*/
public function checkUserNameAvailable(Request $request): JsonResponse
{
$username = $request->request->get('username');
$username = (string) $request->request->get('username');
$retArray = [];

/** @var User|null $user */
$user = $this->user_manager->findOneBy([
'username' => $username,
]);
$user = $this->user_manager->findUserByUsername($username);

$retArray['username_available'] = (bool) $user;
$retArray['statusCode'] = Response::HTTP_OK;
Expand Down
16 changes: 11 additions & 5 deletions src/Api_deprecated/Security/ApiTokenAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\DB\Entity\User\User;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\NonUniqueResultException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -50,6 +51,8 @@ public function supports(Request $request): ?bool

/**
* {@inheritdoc}
*
* @throws NonUniqueResultException
*/
public function authenticate(Request $request): Passport
{
Expand All @@ -59,16 +62,19 @@ public function authenticate(Request $request): Passport
throw new AuthenticationException('Empty token!');
}

/** @var User|null $user */
$user = $this->em->getRepository(User::class)
->findOneBy(['upload_token' => $token])
$qb = $this->em->createQueryBuilder();
$qb->select('u.username')
->from(User::class, 'u')
->where('u.upload_token = :token')
->setParameter('token', $token)
;
$user = $qb->getQuery()->getOneOrNullResult();

if (null === $user) {
if (!$user) {
throw new AuthenticationException('User not found!');
}

return new SelfValidatingPassport(new UserBadge($user->getUserIdentifier()));
return new SelfValidatingPassport(new UserBadge($user['username']));
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/DB/Entity/Project/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Table(name="extension")
* @ORM\Table(
* name="extension",
* indexes={
*
* @ORM\Index(name="internal_title_idx", columns={"internal_title"}),
* }
* )
*
* @ORM\Entity(repositoryClass=ExtensionRepository::class)
*/
Expand Down
12 changes: 11 additions & 1 deletion src/DB/Entity/Project/Program.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@
* name="program",
* indexes={
*
* @ORM\Index(name="rand_idx", columns={"rand"})
* @ORM\Index(name="rand_idx", columns={"rand"}),
* @ORM\Index(name="uploaded_at_idx", columns={"uploaded_at"}),
* @ORM\Index(name="views_idx", columns={"views"}),
* @ORM\Index(name="downloads_idx", columns={"downloads"}),
* @ORM\Index(name="name_idx", columns={"name"}),
* @ORM\Index(name="user_idx", columns={"user_id"}),
* @ORM\Index(name="language_version_idx", columns={"language_version"}),
* @ORM\Index(name="visible_idx", columns={"visible"}),
* @ORM\Index(name="private_idx", columns={"private"}),
* @ORM\Index(name="debug_build_idx", columns={"debug_build"}),
* @ORM\Index(name="flavor_idx", columns={"flavor"}),
* }
* )
*
Expand Down
8 changes: 7 additions & 1 deletion src/DB/Entity/Project/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Table(name="tags")
* @ORM\Table(
* name="tags",
* indexes={
*
* @ORM\Index(name="internal_title_idx", columns={"internal_title"}),
* }
* )
*
* @ORM\Entity(repositoryClass=TagRepository::class)
*/
Expand Down
15 changes: 14 additions & 1 deletion src/DB/Entity/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
*
* @ORM\Table(name="fos_user")
* @ORM\Table(
* name="fos_user",
* indexes={
*
* @ORM\Index(name="upload_token_idx", columns={"upload_token"}),
* @ORM\Index(name="confirmation_token_isx", columns={"confirmation_token"}),
* @ORM\Index(name="username_canonical_idx", columns={"username_canonical"}),
* @ORM\Index(name="email_canonical_idx", columns={"email_canonical"}),
* @ORM\Index(name="scratch_user_id_idx", columns={"scratch_user_id"}),
* @ORM\Index(name="google_id_idx", columns={"google_id"}),
* @ORM\Index(name="facebook_id_idx", columns={"google_id"}),
* @ORM\Index(name="apple_id_idx", columns={"google_id"})
* }
* )
*/
class User extends BaseUser
{
Expand Down
16 changes: 11 additions & 5 deletions src/Security/Authentication/WebView/WebviewAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\DB\Entity\User\User;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\NonUniqueResultException;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
Expand Down Expand Up @@ -61,6 +62,8 @@ public function supports(Request $request): ?bool

/**
* {@inheritdoc}
*
* @throws NonUniqueResultException
*/
public function authenticate(Request $request): Passport
{
Expand All @@ -70,16 +73,19 @@ public function authenticate(Request $request): Passport
throw new AuthenticationException('Empty token!');
}

/** @var User|null $user */
$user = $this->em->getRepository(User::class)
->findOneBy(['upload_token' => $token])
$qb = $this->em->createQueryBuilder();
$qb->select('u.username')
->from(User::class, 'u')
->where('u.upload_token = :token')
->setParameter('token', $token)
;
$user = $qb->getQuery()->getOneOrNullResult();

if (null === $user) {
if (!$user) {
throw new AuthenticationException('User not found!');
}

return new SelfValidatingPassport(new UserBadge($user->getUserIdentifier()));
return new SelfValidatingPassport(new UserBadge($user['username']));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Get most viewed projects
And there are programs:
| id | name | owned by | views | upload time | FileSize | version | language version | flavor | upload_language |
| 1 | project 1 | Catrobat | 10 | 01.08.2014 12:00 | 1048576 | 0.8.5 | 0.999 | pocketcode | en |
| 2 | project 2 | User1 | 50 | 02.08.2014 12:00 | 1048576 | 0.8.5 | 0.982 | luna | fr |
| 2 | project 2 | User1 | 60 | 02.08.2014 12:00 | 1048576 | 0.8.5 | 0.982 | luna | fr |
| 3 | project 3 | Catrobat | 5 | 03.08.2014 12:00 | 1048576 | 0.8.5 | 0.123 | pocketcode | de |
| 4 | project 4 | User2 | 50 | 04.08.2014 12:00 | 1048576 | 0.8.5 | 0.984 | luna | en |
| 5 | project 5 | User1 | 40 | 05.08.2014 12:00 | 1048576 | 0.8.5 | 0.985 | pocketcode | de |
Expand Down

0 comments on commit 33eeaab

Please sign in to comment.