Skip to content

Commit

Permalink
Updated CachingModel to cache table cols by [dsn][table_name] so that…
Browse files Browse the repository at this point in the history
… it works in apps that use multiple dsns
  • Loading branch information
rotimi committed May 13, 2023
1 parent edc6a63 commit 91e2181
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/LeanOrm/CachingModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ protected function fetchTableListFromDB(): array {
}

protected function fetchTableColsFromDB(string $table_name): array {

if(!array_key_exists($this->db_connector->getConnectionName(), static::$cachedFetchedTableColsFromDB)) {

if(array_key_exists($table_name, static::$cachedFetchedTableColsFromDB)) {
static::$cachedFetchedTableColsFromDB[$this->db_connector->getConnectionName()] = [];
}

if(array_key_exists($table_name, static::$cachedFetchedTableColsFromDB[$this->db_connector->getConnectionName()])) {

return static::$cachedFetchedTableColsFromDB[$table_name];
return static::$cachedFetchedTableColsFromDB[$this->db_connector->getConnectionName()][$table_name];
}

static::$cachedFetchedTableColsFromDB[$table_name] = parent::fetchTableColsFromDB($table_name);
static::$cachedFetchedTableColsFromDB[$this->db_connector->getConnectionName()][$table_name] = parent::fetchTableColsFromDB($table_name);

return static::$cachedFetchedTableColsFromDB[$table_name];
return static::$cachedFetchedTableColsFromDB[$this->db_connector->getConnectionName()][$table_name];
}
}

0 comments on commit 91e2181

Please # to comment.