Skip to content

Commit

Permalink
improve:在有需要初始化对象的情况下,才从数据源中获取数据,减少从数据源中获取数据的时间
Browse files Browse the repository at this point in the history
  • Loading branch information
zqhong committed Jul 4, 2017
1 parent b943ffb commit e57e1ea
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/RankingManger.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,19 @@ public function import()
}
}

while (($items = $this->dataSource->get($lastId, $this->fetchNum)) != []) {
foreach ($needInitObjects as $ranking) {
/**@var Ranking $ranking */
$ranking->import($items);
$this->redisClient->set($ranking->getInitKey(), $now);
}
if (!empty($needInitObjects)) {
while (($items = $this->dataSource->get($lastId, $this->fetchNum)) != []) {
foreach ($needInitObjects as $ranking) {
/**@var Ranking $ranking */
$ranking->import($items);
$this->redisClient->set($ranking->getInitKey(), $now);
}

$lastItem = Arr::last($items);
$lastId = $lastItem['id'];
$lastItem = Arr::last($items);
$lastId = $lastItem['id'];
}
}

}

/**
Expand Down

0 comments on commit e57e1ea

Please sign in to comment.