Skip to content

Commit

Permalink
performance improvements (kimai#927)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpapst authored Jul 9, 2019
1 parent eb4aa23 commit cbf9086
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 85 deletions.
30 changes: 12 additions & 18 deletions src/Entity/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@
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
{
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -82,7 +85,6 @@ class Activity implements EntityWithMetaFields

public function __construct()
{
$this->timesheets = new ArrayCollection();
$this->meta = new ArrayCollection();
}

Expand All @@ -91,14 +93,6 @@ public function getId(): ?int
return $this->id;
}

/**
* @return Collection<Timesheet>
*/
public function getTimesheets(): Collection
{
return $this->timesheets;
}

public function getProject(): ?Project
{
return $this->project;
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/ActivityMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/BudgetTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 7 additions & 17 deletions src/Entity/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@
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
{
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -163,7 +162,6 @@ class Customer implements EntityWithMetaFields

public function __construct()
{
$this->projects = new ArrayCollection();
$this->meta = new ArrayCollection();
}

Expand Down Expand Up @@ -352,14 +350,6 @@ public function getTimezone(): ?string
return $this->timezone;
}

/**
* @return Collection<Project>
*/
public function getProjects(): Collection
{
return $this->projects;
}

/**
* @internal only here for symfony forms
* @return Collection|MetaTableTypeInterface[]
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/CustomerMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/MetaTableTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
44 changes: 10 additions & 34 deletions src/Entity/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@
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
{
Expand All @@ -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()
*/
Expand Down Expand Up @@ -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
*
Expand All @@ -98,8 +92,6 @@ class Project implements EntityWithMetaFields

public function __construct()
{
$this->activities = new ArrayCollection();
$this->timesheets = new ArrayCollection();
$this->meta = new ArrayCollection();
}

Expand Down Expand Up @@ -163,22 +155,6 @@ public function getVisible(): bool
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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/ProjectMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 14 additions & 3 deletions src/Entity/Timesheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,23 @@
* @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
{
Expand Down Expand Up @@ -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()
*/
Expand All @@ -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()
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/TimesheetMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
53 changes: 53 additions & 0 deletions src/Migrations/Version20190706224211.php
Original file line number Diff line number Diff line change
@@ -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()
}
}
Loading

0 comments on commit cbf9086

Please sign in to comment.