Merge pull request 'update cache user jira' (#37) from joseph.Update_personnel_allocation into master
Reviewed-on: #37
This commit is contained in:
commit
6694b1f0e1
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Helper\Cache;
|
||||
use Modules\Admin\app\Models\Setting;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Helper\Constant\CacheConstant;
|
||||
use App\Models\User;
|
||||
use App\Services\JiraService;
|
||||
|
||||
class UserJiraCacheHelper {
|
||||
public static $globals = 'users-jira';
|
||||
public static $key = 'users-jira';
|
||||
public static function getCacheSetting(){
|
||||
$users = Cache::get(self::$key, null);
|
||||
if (isset($GLOBALS[self::$globals]) && $users != null)
|
||||
return $GLOBALS[self::$globals];
|
||||
if ($users == null) {
|
||||
$jira_service = new JiraService;
|
||||
$user_db = User::all();
|
||||
$users = $jira_service->getUsersByEmails($user_db);
|
||||
if ($users) {
|
||||
Cache::put(self::$key, json_encode($users), (60 * CacheConstant::$expired) );
|
||||
$users = json_encode($users);
|
||||
} else {
|
||||
$users = null;
|
||||
}
|
||||
}
|
||||
if ($users == null) {
|
||||
$GLOBALS[self::$globals] = null;
|
||||
|
||||
} else {
|
||||
$GLOBALS[self::$globals] = json_decode($users);
|
||||
}
|
||||
return $GLOBALS[self::$globals];
|
||||
}
|
||||
|
||||
public static function cleanCacheSetting(){
|
||||
Cache::forget(self::$key);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Helper\Cache\UserJiraCacheHelper;
|
||||
use App\Models\User;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Promise\Utils;
|
||||
|
|
@ -225,14 +226,12 @@ class JiraService
|
|||
|
||||
public function getAllUserDoing()
|
||||
{
|
||||
$all_users = User::all();
|
||||
$users = $this->getUsersByEmails($all_users);
|
||||
// $projects = $this->getAllProjects();
|
||||
$users = UserJiraCacheHelper::getCacheSetting();
|
||||
$groupedIssues = [];
|
||||
$users_data = [];
|
||||
$user_warning = [];
|
||||
foreach ($users as $user) {
|
||||
$user = $user[0];
|
||||
$user = (array)$user[0];
|
||||
$users_data[$user['displayName']]['user'] = $user;
|
||||
$users_data[$user['displayName']]['total_spent'] = 0;
|
||||
$users_data[$user['displayName']]['total_est'] = 0;
|
||||
|
|
@ -287,7 +286,6 @@ class JiraService
|
|||
|
||||
|
||||
return ['projects' => $groupedIssues, 'users' => $users_data, 'warningList' => $user_warning];
|
||||
// return $projects;
|
||||
}
|
||||
|
||||
public function getDetailIssueByKey($issueKey)
|
||||
|
|
|
|||
Loading…
Reference in New Issue