performance improvements (#927)

This commit is contained in:
Kevin Papst
2019-07-09 03:40:48 +02:00
committed by GitHub
parent eb4aa23577
commit cbf9086e10
15 changed files with 172 additions and 85 deletions

View File

@@ -15,8 +15,18 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Table(name="kimai2_activities")
* @ORM\Table(name="kimai2_activities",
* indexes={
* @ORM\Index(columns={"visible","project_id"}),
* @ORM\Index(columns={"visible","project_id","name"}),
* @ORM\Index(columns={"visible","name"})
* }
* )
* @ORM\Entity(repositoryClass="App\Repository\ActivityRepository")
*
* columns={"visible","name"} => IDX_8811FE1C7AB0E8595E237E06 => activity administration without filter
* columns={"visible","project_id"} => IDX_8811FE1C7AB0E859166D1F9C => activity administration with customer or project filter
* columns={"visible","project_id","name"} => IDX_8811FE1C7AB0E859166D1F9C5E237E06 => activity drop-down for global activities in toolbar or globalsOnly filter in activity administration
*/
class Activity implements EntityWithMetaFields
{
@@ -32,7 +42,7 @@ class Activity implements EntityWithMetaFields
/**
* @var Project|null
*
* @ORM\ManyToOne(targetEntity="App\Entity\Project", inversedBy="activities")
* @ORM\ManyToOne(targetEntity="App\Entity\Project")
* @ORM\JoinColumn(onDelete="CASCADE")
*/
private $project;
@@ -61,13 +71,6 @@ class Activity implements EntityWithMetaFields
*/
private $visible = true;
/**
* @var Timesheet[]|ArrayCollection
*
* @ORM\OneToMany(targetEntity="App\Entity\Timesheet", mappedBy="activity")
*/
private $timesheets;
// keep the trait include exactly here, for placing the column at the correct position
use RatesTrait;
use ColorTrait;
@@ -82,7 +85,6 @@ class Activity implements EntityWithMetaFields
public function __construct()
{
$this->timesheets = new ArrayCollection();
$this->meta = new ArrayCollection();
}
@@ -91,14 +93,6 @@ class Activity implements EntityWithMetaFields
return $this->id;
}
/**
* @return Collection<Timesheet>
*/
public function getTimesheets(): Collection
{
return $this->timesheets;
}
public function getProject(): ?Project
{
return $this->project;

View File

@@ -30,7 +30,7 @@ class ActivityMeta implements MetaTableTypeInterface
* @var Activity
*
* @ORM\ManyToOne(targetEntity="App\Entity\Activity", inversedBy="meta")
* @ORM\JoinColumn(onDelete="CASCADE")
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
* @Assert\NotNull()
*/
private $activity;

View File

@@ -27,7 +27,7 @@ trait BudgetTrait
*
* @var int
*
* @ORM\Column(name="time_budget", type="integer", precision=10, scale=2, nullable=false)
* @ORM\Column(name="time_budget", type="integer", nullable=false)
* @Assert\NotNull()
*/
private $timeBudget = 0;

View File

@@ -15,8 +15,14 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Table(name="kimai2_customers")
* @ORM\Table(name="kimai2_customers",
* indexes={
* @ORM\Index(columns={"visible"})
* }
* )
* @ORM\Entity(repositoryClass="App\Repository\CustomerRepository")
*
* columns={"visible"} => IDX_5A9760447AB0E859 => used in customer dropdown
*/
class Customer implements EntityWithMetaFields
{
@@ -54,13 +60,6 @@ class Customer implements EntityWithMetaFields
*/
private $comment;
/**
* @var Project[]|ArrayCollection
*
* @ORM\OneToMany(targetEntity="App\Entity\Project", mappedBy="customer")
*/
private $projects;
/**
* @var bool
*
@@ -163,7 +162,6 @@ class Customer implements EntityWithMetaFields
public function __construct()
{
$this->projects = new ArrayCollection();
$this->meta = new ArrayCollection();
}
@@ -352,14 +350,6 @@ class Customer implements EntityWithMetaFields
return $this->timezone;
}
/**
* @return Collection<Project>
*/
public function getProjects(): Collection
{
return $this->projects;
}
/**
* @internal only here for symfony forms
* @return Collection|MetaTableTypeInterface[]

View File

@@ -30,7 +30,7 @@ class CustomerMeta implements MetaTableTypeInterface
* @var Customer
*
* @ORM\ManyToOne(targetEntity="App\Entity\Customer", inversedBy="meta")
* @ORM\JoinColumn(onDelete="CASCADE")
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
* @Assert\NotNull()
*/
private $customer;

View File

@@ -44,7 +44,7 @@ trait MetaTableTypeTrait
/**
* @var bool
*
* @ORM\Column(name="visible", type="boolean", nullable=false)
* @ORM\Column(name="visible", type="boolean", nullable=false, options={"default": false})
* @Assert\NotNull()
*/
private $visible = false;

View File

@@ -15,8 +15,16 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Table(name="kimai2_projects")
* @ORM\Table(name="kimai2_projects",
* indexes={
* @ORM\Index(columns={"customer_id","visible","name"}),
* @ORM\Index(columns={"customer_id","visible","id"})
* }
* )
* @ORM\Entity(repositoryClass="App\Repository\ProjectRepository")
*
* columns={"customer_id","visible","name"} => IDX_407F12069395C3F37AB0E8595E237E06 => project administration without filter
* columns={"customer_id","visible","id"} => IDX_407F12069395C3F37AB0E859BF396750 => used in joins between project and customer, eg. dropdowns and activity administration page
*/
class Project implements EntityWithMetaFields
{
@@ -32,7 +40,7 @@ class Project implements EntityWithMetaFields
/**
* @var Customer
*
* @ORM\ManyToOne(targetEntity="App\Entity\Customer", inversedBy="projects")
* @ORM\ManyToOne(targetEntity="App\Entity\Customer")
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
* @Assert\NotNull()
*/
@@ -70,25 +78,11 @@ class Project implements EntityWithMetaFields
*/
private $visible = true;
/**
* @var Activity[]|ArrayCollection
*
* @ORM\OneToMany(targetEntity="App\Entity\Activity", mappedBy="project")
*/
private $activities;
// keep the trait include exactly here, for placing the column at the correct position
use RatesTrait;
use ColorTrait;
use BudgetTrait;
/**
* @var Timesheet[]|ArrayCollection
*
* @ORM\OneToMany(targetEntity="App\Entity\Timesheet", mappedBy="project")
*/
private $timesheets;
/**
* @var ProjectMeta[]|Collection
*
@@ -98,8 +92,6 @@ class Project implements EntityWithMetaFields
public function __construct()
{
$this->activities = new ArrayCollection();
$this->timesheets = new ArrayCollection();
$this->meta = new ArrayCollection();
}
@@ -163,22 +155,6 @@ class Project implements EntityWithMetaFields
return $this->visible;
}
/**
* @return Collection<Timesheet>
*/
public function getTimesheets(): Collection
{
return $this->timesheets;
}
/**
* @return Collection<Activity>
*/
public function getActivities(): Collection
{
return $this->activities;
}
/**
* @return string|null
*/

View File

@@ -30,7 +30,7 @@ class ProjectMeta implements MetaTableTypeInterface
* @var Project
*
* @ORM\ManyToOne(targetEntity="App\Entity\Project", inversedBy="meta")
* @ORM\JoinColumn(onDelete="CASCADE")
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
* @Assert\NotNull()
*/
private $project;

View File

@@ -18,12 +18,23 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\Table(name="kimai2_timesheet",
* indexes={
* @ORM\Index(columns={"user"}),
* @ORM\Index(columns={"activity_id"})
* @ORM\Index(columns={"activity_id"}),
* @ORM\Index(columns={"user","start_time"}),
* @ORM\Index(columns={"start_time"}),
* @ORM\Index(columns={"start_time","end_time"}),
* @ORM\Index(columns={"start_time","end_time","user"}),
* }
* )
* @ORM\Entity(repositoryClass="App\Repository\TimesheetRepository")
* @ORM\HasLifecycleCallbacks()
* @App\Validator\Constraints\Timesheet
*
* columns={"user"} => IDX_4F60C6B18D93D649 => count results for user timesheets
* columns={"activity_id"} => IDX_4F60C6B181C06096 => ???
* columns={"user","start_time"} => IDX_4F60C6B18D93D649502DF587 => recent activities, user timesheet with date filzer
* columns={"start_time"} => IDX_4F60C6B1502DF587 => team timesheets with timerange filter only
* columns={"start_time","end_time"} => IDX_4F60C6B1502DF58741561401 => ???
* columns={"start_time","end_time","user"} => IDX_4F60C6B1502DF587415614018D93D649 => ???
*/
class Timesheet implements EntityWithMetaFields
{
@@ -83,7 +94,7 @@ class Timesheet implements EntityWithMetaFields
/**
* @var Activity
*
* @ORM\ManyToOne(targetEntity="App\Entity\Activity", inversedBy="timesheets")
* @ORM\ManyToOne(targetEntity="App\Entity\Activity")
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
* @Assert\NotNull()
*/
@@ -92,7 +103,7 @@ class Timesheet implements EntityWithMetaFields
/**
* @var Project
*
* @ORM\ManyToOne(targetEntity="App\Entity\Project", inversedBy="timesheets")
* @ORM\ManyToOne(targetEntity="App\Entity\Project")
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
* @Assert\NotNull()
*/

View File

@@ -30,7 +30,7 @@ class TimesheetMeta implements MetaTableTypeInterface
* @var Timesheet
*
* @ORM\ManyToOne(targetEntity="App\Entity\Timesheet", inversedBy="meta")
* @ORM\JoinColumn(onDelete="CASCADE")
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
* @Assert\NotNull()
*/
private $timesheet;

View File

@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace DoctrineMigrations;
use App\Doctrine\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Fix meta-table definitions
*
* @version 1.1
*/
final class Version20190706224211 extends AbstractMigration
{
public function getDescription(): string
{
return 'Fix meta-table definitions';
}
public function up(Schema $schema): void
{
$timesheetMeta = $schema->getTable('kimai2_timesheet_meta');
$timesheetMeta->changeColumn('visible', ['notnull' => true, 'default' => false]);
$timesheetMeta->changeColumn('timesheet_id', ['notnull' => true]);
$projectMeta = $schema->getTable('kimai2_projects_meta');
$projectMeta->changeColumn('visible', ['notnull' => true, 'default' => false]);
$projectMeta->changeColumn('project_id', ['notnull' => true]);
$customerMeta = $schema->getTable('kimai2_customers_meta');
$customerMeta->changeColumn('visible', ['notnull' => true, 'default' => false]);
$customerMeta->changeColumn('customer_id', ['notnull' => true]);
$activityMeta = $schema->getTable('kimai2_activities_meta');
$activityMeta->changeColumn('visible', ['notnull' => true, 'default' => false]);
$activityMeta->changeColumn('activity_id', ['notnull' => true]);
}
public function down(Schema $schema): void
{
// the columns above were created incorrect in migration Version20190617100845 for upgraded systems
// that's why there are no equivalent changes in down()
}
}

View File

@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace DoctrineMigrations;
use App\Doctrine\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Creates several indices to improve speed for default queries.
*
* @version 1.1
*/
final class Version20190706224219 extends AbstractMigration
{
public function getDescription(): string
{
return 'Creates several indices to improve speed for default queries.';
}
public function up(Schema $schema): void
{
$timesheet = $schema->getTable('kimai2_timesheet');
$timesheet->addIndex(['user', 'start_time'], 'IDX_4F60C6B18D93D649502DF587');
$timesheet->addIndex(['start_time'], 'IDX_4F60C6B1502DF587');
$timesheet->addIndex(['start_time', 'end_time'], 'IDX_4F60C6B1502DF58741561401');
$timesheet->addIndex(['start_time', 'end_time', 'user'], 'IDX_4F60C6B1502DF587415614018D93D649');
$activity = $schema->getTable('kimai2_activities');
$activity->addIndex(['visible', 'project_id'], 'IDX_8811FE1C7AB0E859166D1F9C');
$activity->addIndex(['visible', 'project_id', 'name'], 'IDX_8811FE1C7AB0E859166D1F9C5E237E06');
$activity->addIndex(['visible', 'name'], 'IDX_8811FE1C7AB0E8595E237E06');
$project = $schema->getTable('kimai2_projects');
$project->addIndex(['customer_id', 'visible', 'name'], 'IDX_407F12069395C3F37AB0E8595E237E06');
$project->addIndex(['customer_id', 'visible', 'id'], 'IDX_407F12069395C3F37AB0E859BF396750');
$customer = $schema->getTable('kimai2_customers');
$customer->addIndex(['visible'], 'IDX_5A9760447AB0E859');
}
public function down(Schema $schema): void
{
$activity = $schema->getTable('kimai2_activities');
$activity->dropIndex('IDX_8811FE1C7AB0E859166D1F9C');
$activity->dropIndex('IDX_8811FE1C7AB0E859166D1F9C5E237E06');
$activity->dropIndex('IDX_8811FE1C7AB0E8595E237E06');
$customer = $schema->getTable('kimai2_customers');
$customer->dropIndex('IDX_5A9760447AB0E859');
$project = $schema->getTable('kimai2_projects');
$project->dropIndex('IDX_407F12069395C3F37AB0E8595E237E06');
$project->dropIndex('IDX_407F12069395C3F37AB0E859BF396750');
$timesheet = $schema->getTable('kimai2_timesheet');
$timesheet->dropIndex('IDX_4F60C6B18D93D649502DF587');
$timesheet->dropIndex('IDX_4F60C6B1502DF587');
$timesheet->dropIndex('IDX_4F60C6B1502DF587415614018D93D649');
$timesheet->dropIndex('idx_4f60c6b1502df58741561401');
}
}

View File

@@ -27,7 +27,6 @@ class ActivityTest extends TestCase
$this->assertNull($sut->getName());
$this->assertNull($sut->getComment());
$this->assertTrue($sut->getVisible());
self::assertIsIterable($sut->getTimesheets());
$this->assertNull($sut->getFixedRate());
$this->assertNull($sut->getHourlyRate());
$this->assertNull($sut->getColor());

View File

@@ -26,8 +26,6 @@ class CustomerTest extends TestCase
$this->assertNull($sut->getName());
$this->assertNull($sut->getNumber());
$this->assertNull($sut->getComment());
self::assertIsIterable($sut->getProjects());
self::assertEmpty($sut->getProjects());
$this->assertTrue($sut->getVisible());
$this->assertNull($sut->getCompany());

View File

@@ -31,10 +31,6 @@ class ProjectTest extends TestCase
$this->assertTrue($sut->getVisible());
$this->assertNull($sut->getFixedRate());
$this->assertNull($sut->getHourlyRate());
self::assertIsIterable($sut->getTimesheets());
self::assertEmpty($sut->getTimesheets());
self::assertIsIterable($sut->getActivities());
self::assertEmpty($sut->getActivities());
$this->assertNull($sut->getColor());
$this->assertEquals(0.0, $sut->getBudget());
$this->assertEquals(0, $sut->getTimeBudget());