Skip to content

Commit

Permalink
Update date is equal to creation date #9021
Browse files Browse the repository at this point in the history
When creating something the update date is also set, instead of being left to
`null`. This matches what is typically done on filesystem. And most importantly
it allow for huge optimization when sorting things by their latest update, since
we do not need to compute "either creation date or update date". That allows
MariaDB DB to optimize the query, and even more so if we add an index on that
single column.
  • Loading branch information
PowerKiKi committed Oct 10, 2022
1 parent 3b5f31e commit 7e5acf0
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 94 deletions.
9 changes: 1 addition & 8 deletions client/app/admin/admin-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,7 @@ const routes: Routes = [
seo: {
title: 'Réservables',
} as NaturalSeo,
selectedColumns: [
'name',
'code',
'purchasePrice',
'initialPrice',
'periodicPrice',
'latestModification',
],
selectedColumns: ['name', 'code', 'purchasePrice', 'initialPrice', 'periodicPrice', 'updateDate'],
},
},
{
Expand Down
6 changes: 3 additions & 3 deletions client/app/admin/bookables/bookables/bookables.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<span naturalColumnsPickerColumn="purchasePrice">Prix d'achat</span>
<span naturalColumnsPickerColumn="initialPrice">Prix initial</span>
<span naturalColumnsPickerColumn="periodicPrice">Prix périodique</span>
<span naturalColumnsPickerColumn="latestModification">Dernière modification</span>
<span naturalColumnsPickerColumn="updateDate">Dernière modification</span>
<span *ngIf="hasUsage" naturalColumnsPickerColumn="usage">Utilisations</span>
<span *ngIf="hasUsage" naturalColumnsPickerColumn="usageNb">Nombre d'utilisations</span>
<span naturalColumnsPickerColumn="verificationDate">Dernière vérification</span>
Expand Down Expand Up @@ -115,12 +115,12 @@
</td>
</ng-container>

<ng-container matColumnDef="latestModification">
<ng-container matColumnDef="updateDate">
<th mat-header-cell *matHeaderCellDef mat-sort-header class="app-date-column">
Dernière modification
</th>
<td mat-cell *matCellDef="let element">
{{ element.updateDate || element.creationDate | swissDate }}
{{ element.updateDate | swissDate }}
</td>
<td mat-footer-cell *matFooterCellDef></td>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<natural-columns-picker (selectionChange)="selectColumns($event)" [selections]="selectedColumns">
<span naturalColumnsPickerColumn="name">Nom</span>
<span naturalColumnsPickerColumn="owner">Membre</span>
<span naturalColumnsPickerColumn="latestModification">Dernière modification</span>
<span naturalColumnsPickerColumn="updateDate">Dernière modification</span>
<span naturalColumnsPickerColumn="status">Status</span>
<span naturalColumnsPickerColumn="type">Type</span>
<span naturalColumnsPickerColumn="remarks">Remarques</span>
Expand Down Expand Up @@ -74,12 +74,12 @@
</td>
</ng-container>

<ng-container matColumnDef="latestModification">
<ng-container matColumnDef="updateDate">
<th mat-header-cell *matHeaderCellDef mat-sort-header class="app-date-column">
Dernière modification
</th>
<td mat-cell *matCellDef="let element">
{{ element.updateDate || element.creationDate | swissDate }}
{{ element.updateDate | swissDate }}
</td>
<td mat-footer-cell *matFooterCellDef></td>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {PermissionsService} from '../../../shared/services/permissions.service';
styleUrls: ['./expenseClaims.component.scss'],
})
export class ExpenseClaimsComponent extends NaturalAbstractList<ExpenseClaimService> implements OnInit {
public selectedColumns = ['name', 'owner', 'latestModification', 'status', 'type', 'remarks', 'amount'];
public selectedColumns = ['name', 'owner', 'updateDate', 'status', 'type', 'remarks', 'amount'];

public constructor(
expenseClaimService: ExpenseClaimService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ <h2 fxFlex class="mat-headline no-margin">Dépenses et remboursements en attente
<td mat-cell *matCellDef="let expenseClaim">{{ expenseClaim.description }}</td>
</ng-container>

<ng-container matColumnDef="latestModification">
<ng-container matColumnDef="updateDate">
<th mat-header-cell *matHeaderCellDef>Dernière modification</th>
<td mat-cell *matCellDef="let expenseClaim">
{{ expenseClaim.updateDate || expenseClaim.creationDate | date: 'dd.MM.y' }}
{{ expenseClaim.updateDate | date: 'dd.MM.y' }}
</td>
</ng-container>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class FinancesComponent extends NaturalAbstractController implements OnIn
@Input() public user!: CurrentUserForProfile_viewer;

public runningExpenseClaimsDS!: NaturalDataSource<ExpenseClaims_expenseClaims>;
public expenseClaimsColumns = ['name', 'latestModification', 'status', 'type', 'remarks', 'amount', 'cancel'];
public expenseClaimsColumns = ['name', 'updateDate', 'status', 'type', 'remarks', 'amount', 'cancel'];

public ibanLocked = true;

Expand Down
1 change: 0 additions & 1 deletion config/autoload/doctrine.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
],
'datetime_functions' => [],
'string_functions' => [
'greatest' => \DoctrineExtensions\Query\Mysql\Greatest::class,
'if' => \DoctrineExtensions\Query\Mysql\IfElse::class,
'ifnull' => \DoctrineExtensions\Query\Mysql\IfNull::class,
],
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"@angular/router": "^14.1.1",
"@apollo/client": "^3.6.9",
"@ecodev/fab-speed-dial": "^11.0.0",
"@ecodev/natural": "^45.0.1",
"@ecodev/natural-editor": "^45.0.1",
"@ecodev/natural": "^45.2.0",
"@ecodev/natural-editor": "^45.2.0",
"@graphql-tools/mock": "^8.7.1",
"angular-particle-effect-button": "^0.0.50",
"apollo": "^2.34.0",
Expand Down
29 changes: 0 additions & 29 deletions server/Application/Api/Input/Sorting/LatestModification.php

This file was deleted.

39 changes: 39 additions & 0 deletions server/Application/Migration/Version20221010154735.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Application\Migration;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

class Version20221010154735 extends AbstractMigration
{
public function up(Schema $schema): void
{
// Delete all triggers, because they are a huge slow-down when updating each records. They will be recreated after migration
$triggers = $this->connection->executeQuery('SHOW TRIGGERS;')->fetchFirstColumn();
foreach ($triggers as $trigger) {
$this->addSql("DROP TRIGGER `$trigger`");
}

$this->addSql('UPDATE `accounting_document` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `configuration` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `bookable_tag` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `transaction_line` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `user_tag` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `transaction` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `booking` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `bookable_metadata` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `country` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `license` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `log` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `bookable` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `transaction_tag` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `account` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `expense_claim` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `user` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `image` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
$this->addSql('UPDATE `message` SET updater_id = creator_id, update_date = creation_date WHERE updater_id IS NULL AND update_date IS NULL;');
}
}
9 changes: 6 additions & 3 deletions server/Application/Model/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* @API\Filter(field="custom", operator="Application\Api\Input\Operator\SearchOperatorType", type="string"),
* })
* @API\Sorting({
* "Application\Api\Input\Sorting\LatestModification",
* "Application\Api\Input\Sorting\Owner"
* })
*/
Expand Down Expand Up @@ -189,8 +188,12 @@ protected function getOwnerForCreation(): ?User
*/
public function timestampCreation(): void
{
$this->setCreationDate(new Chronos());
$this->setCreator(User::getCurrent());
$now = new Chronos();
$user = User::getCurrent();
$this->setCreationDate($now);
$this->setUpdateDate($now);
$this->setCreator($user);
$this->setUpdater($user);

if (!$this->getOwner()) {
$this->setOwner($this->getOwnerForCreation());
Expand Down
5 changes: 5 additions & 0 deletions tests/ApplicationTest/Api/Input/Sorting/AgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

class AgeTest extends AbstractSorting
{
protected function tearDown(): void
{
User::setCurrent(null);
}

public function testSorting(): void
{
$administrator = new User(User::ROLE_ADMINISTRATOR);
Expand Down
33 changes: 0 additions & 33 deletions tests/ApplicationTest/Api/Input/Sorting/LatestModificationTest.php

This file was deleted.

16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1497,10 +1497,10 @@
dependencies:
tslib "^2.3.1"

"@ecodev/natural-editor@^45.0.1":
version "45.0.1"
resolved "https://registry.yarnpkg.com/@ecodev/natural-editor/-/natural-editor-45.0.1.tgz#64bf66374d6575ea6c8e4d863d3045a5bbb26cf7"
integrity sha512-lAdXR92QUXQKGodOLFiOe+0+lFOolq5C1EJMYMiPPGhPN3S5yEJyDd5fUWPLGdyUHAfezQDLvNOpvM5ebBf2mg==
"@ecodev/natural-editor@^45.2.0":
version "45.2.0"
resolved "https://registry.yarnpkg.com/@ecodev/natural-editor/-/natural-editor-45.2.0.tgz#a46a1a749b7166a3d5f863d9ea9874ae90a684e2"
integrity sha512-jcd+3i3/pRxKyQ6Y2bQD8yAzqn9SyBH/kh9314imJ2R9wNwwPc7ZH7/XLTEqpnHOdY/E0uqNM5pQOKG/h7tk4Q==
dependencies:
"@types/prosemirror-commands" "^1.0.4"
"@types/prosemirror-dropcursor" "^1.0.3"
Expand Down Expand Up @@ -1529,10 +1529,10 @@
prosemirror-view "^1.23.5"
tslib "^2.3.0"

"@ecodev/natural@^45.0.1":
version "45.0.1"
resolved "https://registry.yarnpkg.com/@ecodev/natural/-/natural-45.0.1.tgz#4e102121fe7d49d072accb243f11ec773673f41e"
integrity sha512-E4FbzYYjiawlifo9C5xd5475WKKbfDjp1K6n95cEBf1WIdTKg7hz3zkmxEH8c3GpaFexoSnIgboO6mPALQeXOA==
"@ecodev/natural@^45.2.0":
version "45.2.0"
resolved "https://registry.yarnpkg.com/@ecodev/natural/-/natural-45.2.0.tgz#0ed34a4ee41b2d5af3306782aaba08cfe938ea29"
integrity sha512-1kGc9OExJmEHkRrWjqQ+UutTsET97GDDQnpGZTvL2IM8eREDT6zzRe3+XS41kZhhaTmb1bHNnR3S49DOJEj5wg==
dependencies:
tslib "^2.3.1"

Expand Down

0 comments on commit 7e5acf0

Please sign in to comment.