]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Use created_at as default sort
authorJeremy Benoist <jeremy.benoist@gmail.com>
Fri, 4 Nov 2016 06:56:04 +0000 (07:56 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Fri, 4 Nov 2016 06:56:04 +0000 (07:56 +0100)
With index (following https://github.com/wallabag/wallabag/pull/2534)

app/DoctrineMigrations/Version20161104073720.php [new file with mode: 0644]
src/Wallabag/CoreBundle/Repository/EntryRepository.php

diff --git a/app/DoctrineMigrations/Version20161104073720.php b/app/DoctrineMigrations/Version20161104073720.php
new file mode 100644 (file)
index 0000000..16503b4
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+namespace Application\Migrations;
+
+use Doctrine\DBAL\Migrations\AbstractMigration;
+use Doctrine\DBAL\Schema\Schema;
+use Symfony\Component\DependencyInjection\ContainerAwareInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+class Version20161104073720 extends AbstractMigration implements ContainerAwareInterface
+{
+    /**
+     * @var ContainerInterface
+     */
+    private $container;
+
+    public function setContainer(ContainerInterface $container = null)
+    {
+        $this->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)
+    {
+
+    }
+}
index 14616d8889e7dc2f2d60d93b60beb73e9e87e15f..61be5220149771143f573aa27127fb461b9f9a6f 100644 (file)
@@ -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')
         ;
     }