]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #2702 from wallabag/add-index-uuid
authorNicolas LÅ“uillet <nicolas@loeuillet.org>
Thu, 29 Dec 2016 09:54:07 +0000 (10:54 +0100)
committerGitHub <noreply@github.com>
Thu, 29 Dec 2016 09:54:07 +0000 (10:54 +0100)
Added index on entry.uuid

Makefile
app/DoctrineMigrations/Version20160410190541.php
app/DoctrineMigrations/Version20161214094403.php [new file with mode: 0644]
src/Wallabag/CoreBundle/Controller/EntryController.php
src/Wallabag/CoreBundle/Entity/Entry.php
tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php

index 83c5f37ad78610d12e49211d3f6c0fc1b8bb752f..b33352616488d2c8a2c3a13d674f73714184eaf1 100755 (executable)
--- a/Makefile
+++ b/Makefile
@@ -27,8 +27,7 @@ build: ## Run grunt
        @grunt
 
 test: ## Launch wallabag testsuite
-       @if [ ! -d "vendor/phpunit" ]; then composer install; fi
-       @ant prepare && vendor/phpunit/phpunit/phpunit -v
+       @ant prepare && bin/simple-phpunit -v
 
 release: ## Create a package. Need a VERSION parameter (eg: `make release VERSION=master`).
 ifndef VERSION
index 0cdec00852dd1a715a9898dd7e5c02d56f06b0d4..f166a32513cd7ac90eef9ef26aee7306acb45e29 100644 (file)
@@ -31,10 +31,11 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI
     {
         $entryTable = $schema->getTable($this->getTable('entry'));
 
-        $this->skipIf($entryTable->hasColumn('uuid'), 'It seems that you already played this migration.');
+        $this->skipIf($entryTable->hasColumn('uid'), 'It seems that you already played this migration.');
 
-        $entryTable->addColumn('uuid', 'guid', [
+        $entryTable->addColumn('uid', 'string', [
             'notnull' => false,
+            'length' => 23,
         ]);
         $this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('share_public', '1', 'entry')");
     }
@@ -45,7 +46,7 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI
     public function down(Schema $schema)
     {
         $entryTable = $schema->getTable($this->getTable('entry'));
-        $entryTable->dropColumn('uuid');
+        $entryTable->dropColumn('uid');
 
         $this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'share_public'");
     }
diff --git a/app/DoctrineMigrations/Version20161214094403.php b/app/DoctrineMigrations/Version20161214094403.php
new file mode 100644 (file)
index 0000000..5948b5f
--- /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;
+
+/**
+ * Added index on wallabag_entry.uid
+ */
+class Version20161214094403 extends AbstractMigration implements ContainerAwareInterface
+{
+    /**
+     * @var ContainerInterface
+     */
+    private $container;
+
+    private $indexName = 'IDX_entry_uid';
+
+    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)
+    {
+        $entryTable = $schema->getTable($this->getTable('entry'));
+        $this->skipIf($entryTable->hasIndex($this->indexName), 'It seems that you already played this migration.');
+
+        $entryTable->addIndex(['uid'], $this->indexName);
+    }
+
+    /**
+     * @param Schema $schema
+     */
+    public function down(Schema $schema)
+    {
+        $entryTable = $schema->getTable($this->getTable('entry'));
+        $this->skipIf(false === $entryTable->hasIndex($this->indexName), 'It seems that you already played this migration.');
+
+        $entryTable->dropIndex($this->indexName);
+    }
+}
index b03f49eda339efe7af80441d9a46b0710e99a056..f7398e69ed939bcbcc4a6244b689975c14948a33 100644 (file)
@@ -539,8 +539,8 @@ class EntryController extends Controller
     {
         $this->checkUserAction($entry);
 
-        if (null === $entry->getUuid()) {
-            $entry->generateUuid();
+        if (null === $entry->getUid()) {
+            $entry->generateUid();
 
             $em = $this->getDoctrine()->getManager();
             $em->persist($entry);
@@ -548,7 +548,7 @@ class EntryController extends Controller
         }
 
         return $this->redirect($this->generateUrl('share_entry', [
-            'uuid' => $entry->getUuid(),
+            'uid' => $entry->getUid(),
         ]));
     }
 
@@ -565,7 +565,7 @@ class EntryController extends Controller
     {
         $this->checkUserAction($entry);
 
-        $entry->cleanUuid();
+        $entry->cleanUid();
 
         $em = $this->getDoctrine()->getManager();
         $em->persist($entry);
@@ -581,7 +581,7 @@ class EntryController extends Controller
      *
      * @param Entry $entry
      *
-     * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry")
+     * @Route("/share/{uid}", requirements={"uid" = ".+"}, name="share_entry")
      * @Cache(maxage="25200", smaxage="25200", public=true)
      *
      * @return \Symfony\Component\HttpFoundation\Response
index 3ae5334f3192788a8acc3beda35326df2061c521..7276b437cd01e8503507515003e15e1c5fcb04af 100644 (file)
@@ -22,7 +22,10 @@ use Wallabag\AnnotationBundle\Entity\Annotation;
  * @ORM\Table(
  *     name="`entry`",
  *     options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"},
- *     indexes={@ORM\Index(name="created_at", columns={"created_at"})}
+ *     indexes={
+ *         @ORM\Index(name="created_at", columns={"created_at"}),
+ *         @ORM\Index(name="uid", columns={"uid"})
+ *     }
  * )
  * @ORM\HasLifecycleCallbacks()
  * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
@@ -44,11 +47,11 @@ class Entry
     /**
      * @var string
      *
-     * @ORM\Column(name="uuid", type="text", nullable=true)
+     * @ORM\Column(name="uid", type="string", length=23, nullable=true)
      *
      * @Groups({"entries_for_user", "export_all"})
      */
-    private $uuid;
+    private $uid;
 
     /**
      * @var string
@@ -649,34 +652,34 @@ class Entry
     /**
      * @return string
      */
-    public function getUuid()
+    public function getUid()
     {
-        return $this->uuid;
+        return $this->uid;
     }
 
     /**
-     * @param string $uuid
+     * @param string $uid
      *
      * @return Entry
      */
-    public function setUuid($uuid)
+    public function setUid($uid)
     {
-        $this->uuid = $uuid;
+        $this->uid = $uid;
 
         return $this;
     }
 
-    public function generateUuid()
+    public function generateUid()
     {
-        if (null === $this->uuid) {
+        if (null === $this->uid) {
             // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
-            $this->uuid = uniqid('', true);
+            $this->uid = uniqid('', true);
         }
     }
 
-    public function cleanUuid()
+    public function cleanUid()
     {
-        $this->uuid = null;
+        $this->uid = null;
     }
 
     /**
index c347cca5ad2ab05ba2acb3783fa432fd2ad13307..06ed2db60e4ec6041b21510d8d29cd2e09a601b6 100644 (file)
@@ -810,15 +810,15 @@ class EntryControllerTest extends WallabagCoreTestCase
             ->getRepository('WallabagCoreBundle:Entry')
             ->findOneByUser($this->getLoggedInUserId());
 
-        // no uuid
-        $client->request('GET', '/share/'.$content->getUuid());
+        // no uid
+        $client->request('GET', '/share/'.$content->getUid());
         $this->assertEquals(404, $client->getResponse()->getStatusCode());
 
-        // generating the uuid
+        // generating the uid
         $client->request('GET', '/share/'.$content->getId());
         $this->assertEquals(302, $client->getResponse()->getStatusCode());
 
-        // follow link with uuid
+        // follow link with uid
         $crawler = $client->followRedirect();
         $this->assertEquals(200, $client->getResponse()->getStatusCode());
         $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
@@ -832,7 +832,7 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         // sharing is now disabled
         $client->getContainer()->get('craue_config')->set('share_public', 0);
-        $client->request('GET', '/share/'.$content->getUuid());
+        $client->request('GET', '/share/'.$content->getUid());
         $this->assertEquals(404, $client->getResponse()->getStatusCode());
 
         $client->request('GET', '/view/'.$content->getId());
@@ -843,7 +843,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         $this->assertEquals(302, $client->getResponse()->getStatusCode());
 
         // share is now disable
-        $client->request('GET', '/share/'.$content->getUuid());
+        $client->request('GET', '/share/'.$content->getUid());
         $this->assertEquals(404, $client->getResponse()->getStatusCode());
     }