Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Commit

Permalink
Merge pull request #154 from Hounddog/caching_bug_modules
Browse files Browse the repository at this point in the history
Changed caching and filtering of modules
  • Loading branch information
akrabat committed Nov 6, 2013
2 parents 91e114d + c635924 commit 41cd2dc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 38 deletions.
2 changes: 1 addition & 1 deletion module/Application/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
),
'view_helpers' => array(
'factories' => array(
'flashMessenger' => function($sm) {
'flashMessenger' => function ($sm) {
$sm = $sm->getServiceLocator();
$plugin = $sm->get('ControllerPluginManager')->get('flashMessenger');

Expand Down
4 changes: 2 additions & 2 deletions module/User/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function bootstrap(ModuleManager $moduleManager, ApplicationInterface $ap
$em = $app->getEventManager()->getSharedManager();
$sm = $app->getServiceManager();

$em->attach('ScnSocialAuth\Authentication\Adapter\HybridAuth','githubToLocalUser', function($e) {
$em->attach('ScnSocialAuth\Authentication\Adapter\HybridAuth','githubToLocalUser', function ($e) {
$localUser = $e->getTarget();
$userProfile = $e->getParam('userProfile');
$nickname = substr(
Expand All @@ -24,7 +24,7 @@ public function bootstrap(ModuleManager $moduleManager, ApplicationInterface $ap
$localUser->setPhotoUrl($userProfile->photoURL);
});

$em->attach('EdpGithub\Client', 'api', function($e) use ($sm) {
$em->attach('EdpGithub\Client', 'api', function ($e) use ($sm) {
$hybridAuth = $sm->get('HybridAuth');
$adapter = $hybridAuth->getAdapter('github');

Expand Down
8 changes: 4 additions & 4 deletions module/ZfModule/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getServiceConfig()
{
return array(
'factories' => array(
'zfmodule_cache' => function($sm) {
'zfmodule_cache' => function ($sm) {
$config = $sm->get('Config');
$storage = StorageFactory::factory($config['zfmodule']['cache']);

Expand All @@ -61,16 +61,16 @@ public function getServiceConfig()
$mapper->setHydrator(new Mapper\ModuleHydrator());
return $mapper;
},
'zfmodule_service_module' => function($sm) {
'zfmodule_service_module' => function ($sm) {
$service = new Service\Module;
return $service;
},
'zfmodule_service_repository' => function($sm) {
'zfmodule_service_repository' => function ($sm) {
$service = new Service\Repository;
$service->setApi($sm->get('EdpGithub\Client'));
return $service;
},
/*'github_client' => function($sm) {
/*'github_client' => function ($sm) {
$hybridAuth = $sm->get('HybridAuth');
$adapter = $hybridAuth->getAdapter('github');
$token = $adapter->getAccessToken();
Expand Down
45 changes: 16 additions & 29 deletions module/ZfModule/src/ZfModule/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,48 +125,35 @@ public function fetchModules($repos, $cacheKey)
$cache = $sl->get('zfmodule_cache');

$repositories = array();
//fetch only modules from github
foreach($repos as $repo) {
//Need to see first if any repository has been updated

foreach($repos as $key => $repo) {
//Verify if repos have been modified
$httpClient = $client->getHttpClient();
$response= $httpClient->getResponse();
$response = $httpClient->getResponse();
if($response->getStatusCode() == 304) {
if($cache->hasItem($cacheKey . '-github')) {
$repositories = $cache->getItem($cacheKey . '-github');
break;
}
} elseif ($cache->hasItem($cacheKey . '-github')) {
$cache->removeItem($cacheKey . '-github');
}
if(!$repo->fork && $repo->permissions->push) {
if($this->getModuleService()->isModule($repo)) {
$repositories[] = $repo;
}

if($repo->fork || !$repo->permissions->push || !$this->getModuleService()->isModule($repo) ) {
continue;
}
}
//save list of modules to cache
if(!$cache->hasItem($cacheKey . '-github')) {
$cache->setItem($cacheKey . '-github', $repositories);
}

//check if cache for modules exist
if(!$cache->hasItem($cacheKey)) {
//check if module is in database
foreach($repositories as $key => $repo) {
$module = $mapper->findByName($repo->name);
if($module) {
unset($repositories[$key]);
}
$module = $mapper->findByName($repo->name);
if($module) {
continue;
}
//save database mapped list to cache
$cache->setItem($cacheKey , $repositories);
// create cache tags
$identity = $this->zfcUserAuthentication()->getIdentity();

$tags = array($identity->getUsername() . '-' . $identity->getId());
$cache->setTags($cacheKey, $tags);
} else {
$repositories = $cache->getItem($cacheKey);
$repositories[] = $repo;
}

//save list of modules to cache
$cache->setItem($cacheKey . '-github', $repositories);

return $repositories;
}

Expand Down
4 changes: 2 additions & 2 deletions module/ZfModule/src/ZfModule/Mapper/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function pagination($page, $limit, $query = null, $orderBy = null, $sort
}

if(null !== $query) {
$spec = function ( $where) use ($query) {
$spec = function ($where) use ($query) {
$where->like('name', '%'.$query.'%')->or->like('description', '%'.$query.'%');
};
$select->where($spec);
Expand Down Expand Up @@ -72,7 +72,7 @@ public function findByLike($query, $limit = null, $orderBy = null, $sort = 'ASC'
$select->limit($limit);
}

$spec = function ( $where) use ($query) {
$spec = function ($where) use ($query) {
$where->like('name', '%'.$query.'%')->or->like('description', '%'.$query.'%');
};
$select->where($spec);
Expand Down

0 comments on commit 41cd2dc

Please sign in to comment.