Skip to content

Commit 9aa89e9

Browse files
committed
update commit hash logic
1 parent 53f7a9f commit 9aa89e9

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/Service/Action/Committer.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,20 @@ public function commit(int $actionId, ?string $config, UserContext $context): vo
4646

4747
$previousHash = $this->actionCommitTable->findCurrentHash($actionId);
4848

49-
$now = LocalDateTime::now();
50-
$hash = sha1($actionId . $context->getUserId() . $previousHash . $config . $now->toString());
49+
$hash = sha1($context->getTenantId() . $context->getUserId() . $actionId . $previousHash . $config);
50+
51+
$existing = $this->actionCommitTable->findOneByCommitHash($hash);
52+
if ($existing instanceof Table\Generated\ActionCommitRow) {
53+
return;
54+
}
5155

5256
$row = new Table\Generated\ActionCommitRow();
5357
$row->setActionId($actionId);
5458
$row->setUserId($context->getUserId());
5559
$row->setPrevHash($previousHash ?? '');
5660
$row->setCommitHash($hash);
5761
$row->setConfig($config);
58-
$row->setInsertDate($now);
62+
$row->setInsertDate(LocalDateTime::now());
5963
$this->actionCommitTable->create($row);
6064
}
6165
}

src/Service/Schema/Committer.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,20 @@ public function commit(int $schemaId, string $source, UserContext $context): voi
4242
{
4343
$previousHash = $this->schemaCommitTable->findCurrentHash($schemaId);
4444

45-
$now = LocalDateTime::now();
46-
$hash = sha1($schemaId . $context->getUserId() . $previousHash . $source . $now->toString());
45+
$hash = sha1($context->getTenantId() . $context->getUserId() . $schemaId . $previousHash . $source);
46+
47+
$existing = $this->schemaCommitTable->findOneByCommitHash($hash);
48+
if ($existing instanceof Table\Generated\SchemaCommitRow) {
49+
return;
50+
}
4751

4852
$row = new Table\Generated\SchemaCommitRow();
4953
$row->setSchemaId($schemaId);
5054
$row->setUserId($context->getUserId());
5155
$row->setPrevHash($previousHash ?? '');
5256
$row->setCommitHash($hash);
5357
$row->setSource($source);
54-
$row->setInsertDate($now);
58+
$row->setInsertDate(LocalDateTime::now());
5559
$this->schemaCommitTable->create($row);
5660
}
5761
}

0 commit comments

Comments
 (0)