diff --git a/daemon/Dockerfile b/daemon/Dockerfile index 18e69a8..0fbe116 100644 --- a/daemon/Dockerfile +++ b/daemon/Dockerfile @@ -1,4 +1,4 @@ -FROM cache_practices_daemon:latest +FROM timurns/cache_practices_daemon:latest ENV DIR="/var/daemon" \ MYSQL_HOST="mysql" \ diff --git a/daemon/dependencies.json b/daemon/dependencies.json index 0146be8..116326f 100644 --- a/daemon/dependencies.json +++ b/daemon/dependencies.json @@ -14,7 +14,8 @@ "table_name": "bookstore.categories" }, { - "table_name": "bookstore.authors_books" + "table_name": "bookstore.authors_books", + "primary_key": "id_book" }, { "table_name": "bookstore.authors" @@ -43,4 +44,4 @@ } ] } -] \ No newline at end of file +] diff --git a/daemon/src/EventProcessors/InsertEventProcessor.php b/daemon/src/EventProcessors/InsertEventProcessor.php index 40d7f4b..9613448 100644 --- a/daemon/src/EventProcessors/InsertEventProcessor.php +++ b/daemon/src/EventProcessors/InsertEventProcessor.php @@ -6,6 +6,43 @@ class InsertEventProcessor extends BaseEventProcessor { public function process(): void { - // TODO: Implement process() method. + if (!$this->eventInfo['changedRows'] + || empty($this->eventInfo['values']) + || empty($this->eventInfo['tableMap']) + || !\count($this->eventInfo['values']) + ) { + return; + } + + /** @var TableMap $tableMap */ + $tableMap = $this->eventInfo['tableMap']; + /** @var InvalidateRule[] $rules */ + $rules = $this->getRulesFromDependencies($tableMap); + + #var_export($this->eventInfo); + #var_export($rules); + + foreach ($rules as $rule) { + $warmer = $this->getWarmerBy($rule->getHashName()); + + if ($rule->isSingleKey()) { + $warmer->fetchAllEntities(); + #$warmer->warm($warmer->getKey([]), $warmer->getEntities()); + foreach ($warmer->getEntities() as $entity) + $warmer->warm($warmer->getKey($entity), $entity); + } elseif ($rule->hasPrimaryKey()) { + foreach ($this->eventInfo['values'] as $change) { + #echo "CHANGE"; + #var_export($change); + $pk = $rule->getPrimaryKey(); + $id = $change[$pk]; + #echo "ID is " . $id; + $entity = $warmer->fetchById($id); + #var_export($entity); + if (!empty($entity)) + $warmer->warm($warmer->getKey($entity), $entity); + } + } + } } -} \ No newline at end of file +}