From 1e7b04d4eada9b1a9064cbd8c9bf2de63ae63e76 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 4 Nov 2016 07:56:04 +0100 Subject: [PATCH 1/2] Use created_at as default sort With index (following https://github.com/wallabag/wallabag/pull/2534) --- .../Version20161104073720.php | 53 +++++++++++++++++++ .../CoreBundle/Repository/EntryRepository.php | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 app/DoctrineMigrations/Version20161104073720.php diff --git a/app/DoctrineMigrations/Version20161104073720.php b/app/DoctrineMigrations/Version20161104073720.php new file mode 100644 index 000000000..16503b4b0 --- /dev/null +++ b/app/DoctrineMigrations/Version20161104073720.php @@ -0,0 +1,53 @@ +container = $container; + } + + private function getTable($tableName) + { + return $this->container->getParameter('database_table_prefix') . $tableName; + } + + /** + * @param Schema $schema + */ + public function up(Schema $schema) + { + switch ($this->connection->getDatabasePlatform()->getName()) { + case 'sqlite': + $this->addSql('CREATE INDEX `created_at` ON `'.$this->getTable('entry').'` (`created_at` DESC)'); + break; + + case 'mysql': + $this->addSql('ALTER TABLE '.$this->getTable('entry').' ADD INDEX created_at (created_at);'); + break; + + case 'postgresql': + $this->addSql('CREATE INDEX created_at ON '.$this->getTable('entry').' (created_at DESC)'); + } + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + + } +} diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 14616d888..61be52201 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -22,7 +22,7 @@ class EntryRepository extends EntityRepository return $this->createQueryBuilder('e') ->leftJoin('e.user', 'u') ->andWhere('u.id = :userId')->setParameter('userId', $userId) - ->orderBy('e.id', 'desc') + ->orderBy('e.createdAt', 'desc') ; } From 7e9c1d65b1e43364011fed133078f1c5ea02440d Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 4 Nov 2016 08:02:02 +0100 Subject: [PATCH 2/2] Add index into Table definition --- src/Wallabag/CoreBundle/Entity/Entry.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index dd0f7e672..f59c445f3 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -19,7 +19,11 @@ use Wallabag\AnnotationBundle\Entity\Annotation; * * @XmlRoot("entry") * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository") - * @ORM\Table(name="`entry`", options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"}) + * @ORM\Table( + * name="`entry`", + * options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"}, + * indexes={@ORM\Index(name="created_at", columns={"created_at"})} + * ) * @ORM\HasLifecycleCallbacks() * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())") */