1
0
Fork 0

Create lookup table for installed packages in only one place

pull/667/head
Nils Adermann 2012-04-27 17:50:53 +02:00
parent 5daeacf0ac
commit f4ae88a5d6
1 changed files with 17 additions and 11 deletions

View File

@ -35,6 +35,8 @@ class Solver
protected $decisionMap; protected $decisionMap;
protected $installedMap; protected $installedMap;
protected $installedPackages;
protected $packageToFeatureRule = array(); protected $packageToFeatureRule = array();
public function __construct(PolicyInterface $policy, Pool $pool, RepositoryInterface $installed) public function __construct(PolicyInterface $policy, Pool $pool, RepositoryInterface $installed)
@ -667,14 +669,20 @@ class Solver
} }
} }
protected function setupInstalledMap()
{
$this->installedPackages = $this->installed->getPackages();
$this->installedMap = array();
foreach ($this->installedPackages as $package) {
$this->installedMap[$package->getId()] = $package;
}
}
public function solve(Request $request) public function solve(Request $request)
{ {
$this->jobs = $request->getJobs(); $this->jobs = $request->getJobs();
$installedPackages = $this->installed->getPackages();
$this->installedMap = array(); $this->setupInstalledMap();
foreach ($installedPackages as $package) {
$this->installedMap[$package->getId()] = $package;
}
if (version_compare(PHP_VERSION, '5.3.4', '>=')) { if (version_compare(PHP_VERSION, '5.3.4', '>=')) {
$this->decisionMap = new \SplFixedArray($this->pool->getMaxId() + 1); $this->decisionMap = new \SplFixedArray($this->pool->getMaxId() + 1);
@ -695,18 +703,18 @@ class Solver
switch ($job['cmd']) { switch ($job['cmd']) {
case 'update-all': case 'update-all':
foreach ($installedPackages as $package) { foreach ($this->installedMap as $package) {
$this->updateMap[$package->getId()] = true; $this->updateMap[$package->getId()] = true;
} }
break; break;
} }
} }
foreach ($installedPackages as $package) { foreach ($this->installedMap as $package) {
$this->addRulesForPackage($package); $this->addRulesForPackage($package);
} }
foreach ($installedPackages as $package) { foreach ($this->installedMap as $package) {
$this->addRulesForUpdatePackages($package); $this->addRulesForUpdatePackages($package);
} }
@ -724,7 +732,7 @@ class Solver
// solver_addrpmrulesforweak(solv, &addedmap); // solver_addrpmrulesforweak(solv, &addedmap);
foreach ($installedPackages as $package) { foreach ($this->installedMap as $package) {
$updates = $this->policy->findUpdatePackages($this, $this->pool, $this->installedMap, $package); $updates = $this->policy->findUpdatePackages($this, $this->pool, $this->installedMap, $package);
$rule = $this->createUpdateRule($package, $updates, Rule::RULE_INTERNAL_ALLOW_UPDATE, (string) $package); $rule = $this->createUpdateRule($package, $updates, Rule::RULE_INTERNAL_ALLOW_UPDATE, (string) $package);
@ -1467,8 +1475,6 @@ class Solver
$minimizationSteps = 0; $minimizationSteps = 0;
$installedPos = 0; $installedPos = 0;
$this->installedPackages = $this->installed->getPackages();
while (true) { while (true) {
if (1 === $level) { if (1 === $level) {