Skip to content

Commit

Permalink
调整:连接源缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
dxkite committed Dec 22, 2019
1 parent 6277c81 commit 732a362
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion suda/src/application/database/Database.php
Expand Up @@ -24,6 +24,11 @@ class Database
*/
protected static $application;

/**
* @var DataSource[]
*/
protected static $dataSource = [];

/**
* 从应用创建表
*
Expand Down Expand Up @@ -73,6 +78,9 @@ public static function getDataSource(string $name)
*/
public static function getDataSourceFrom(ApplicationResource $resource, string $groupName)
{
if (array_key_exists($groupName, static::$dataSource)) {
return static::$dataSource[$groupName];
}
$group = $groupName === 'default' ? '': '-'. $groupName;
$dataSourceConfigPath = $resource->getConfigResourcePath('config/data-source'.$group);
$dataSource = new DataSource;
Expand All @@ -93,7 +101,7 @@ public static function getDataSourceFrom(ApplicationResource $resource, string $
}
}
}
return $dataSource;
return static::$dataSource[$groupName] = $dataSource;
}


Expand Down

0 comments on commit 732a362

Please sign in to comment.