update cache user jira

This commit is contained in:
JOSEPH LE 2024-09-18 16:30:34 +07:00
parent 84a636ea22
commit 3830315a9d
2 changed files with 43 additions and 5 deletions

View File

@ -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);
}
}

View File

@ -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)