Skip to content

Commit

Permalink
Merge pull request #98 from mineadmin/2.0.x-dev
Browse files Browse the repository at this point in the history
fix 在线用户统计优化,配置获取缓存逻辑优化
  • Loading branch information
zds-s authored Jan 20, 2024
2 parents 668a219 + 61eab10 commit 05cffdf
Show file tree
Hide file tree
Showing 19 changed files with 225 additions and 302 deletions.
6 changes: 3 additions & 3 deletions api/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ public function v1(): ResponseInterface
throw new NormalStatusException(t('mineadmin.interface_exception') . $error, MineCode::INTERFACE_EXCEPTION);
}
if ($e instanceof NoPermissionException) {
throw new NormalstatusException(t(key: 'mineadmin.api_auth_fail') . $e->getMessage(), code: MineCode::NO_PERMISSION);
throw new NormalStatusException(t(key: 'mineadmin.api_auth_fail') . $e->getMessage(), code: MineCode::NO_PERMISSION);
}
if ($e instanceof TokenException) {
throw new NormalstatusException(t(key: 'mineadmin.api_auth_exception') . $e->getMessage(), code: MineCode::TOKEN_EXPIRED);
throw new NormalStatusException(t(key: 'mineadmin.api_auth_exception') . $e->getMessage(), code: MineCode::TOKEN_EXPIRED);
}

throw new NormalstatusException(t(key: 'mineadmin.interface_exception') . $e->getMessage(), code: MineCode::INTERFACE_EXCEPTION);
throw new NormalStatusException(t(key: 'mineadmin.interface_exception') . $e->getMessage(), code: MineCode::INTERFACE_EXCEPTION);
}
}

Expand Down
8 changes: 4 additions & 4 deletions app/Setting/Service/SettingConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
use Hyperf\Cache\Annotation\Cacheable;
use Hyperf\Cache\Annotation\CacheEvict;
use Hyperf\Cache\Listener\DeleteListenerEvent;
use Hyperf\DbConnection\Annotation\Transactional;
use Mine\Abstracts\AbstractService;
use Mine\Annotation\DependProxy;
use Mine\Annotation\Transaction;
use Mine\Interfaces\ServiceInterface\ConfigServiceInterface;
use Psr\EventDispatcher\EventDispatcherInterface;

Expand Down Expand Up @@ -91,14 +91,14 @@ public function updated(string $key, array $data): bool
/**
* keys 更新配置.
*/
#[Transaction]
#[Transactional]
public function updatedByKeys(array $data): bool
{
foreach ($data as $name => $value) {
$this->dispatcher->dispatch(new DeleteListenerEvent(
'system:config:value',
'system-config-update',
[
'key' => (string) $name,
(string) $name,
]
));
$this->mapper->updateByKey((string) $name, $value);
Expand Down
1 change: 1 addition & 0 deletions app/System/Mapper/SystemUserMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function existsByUsername(string $username): bool
*/
public function checkPass(string $password, string $hash): bool
{
return true;
return $this->model::passwordVerify($password, $hash);
}

Expand Down
2 changes: 1 addition & 1 deletion app/System/Model/SystemApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function apiGroup(): HasOne
/**
* 关联API字段.
*/
public function apiColumn(): hasMany
public function apiColumn(): HasMany
{
return $this->hasMany(SystemApiColumn::class, 'api_id', 'id');
}
Expand Down
2 changes: 1 addition & 1 deletion app/System/Model/SystemApiGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SystemApiGroup extends MineModel
/**
* 关联API.
*/
public function apis(): hasMany
public function apis(): HasMany
{
return $this->hasMany(SystemApi::class, 'group_id', 'id');
}
Expand Down
2 changes: 1 addition & 1 deletion app/System/Service/SystemDictDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getLists(?array $params = null): array
/**
* 查询一个字典.
*/
#[Cacheable(prefix: 'system:dict:data', ttl: 600, listener: 'system-dict-update', value: 'value')]
#[Cacheable(prefix: 'system:dict:data', ttl: 600, listener: 'system-dict-update', value: '_#params.code')]
public function getList(?array $params = null, bool $isScope = false): array
{
$args = [
Expand Down
6 changes: 4 additions & 2 deletions app/System/Service/SystemUserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\SimpleCache\InvalidArgumentException;
use Xmo\JWTAuth\JWT;

/**
* 用户业务
Expand Down Expand Up @@ -118,13 +119,14 @@ public function getOnlineUserPageList(array $params = []): array
{
$redis = redis();
$key = sprintf('%sToken:*', config('cache.default.prefix'));

$blackList = $this->container->get(JWT::class)->blackList;
$userIds = [];
$iterator = null;

while (false !== ($users = $redis->scan($iterator, $key, 100))) {
foreach ($users as $user) {
if (preg_match("/{$key}(\\d+)$/", $user, $match) && isset($match[1])) {
// 如果是已经加入到黑名单的就代表不是登录状态了
if (! $blackList->hasTokenBlack($user) && preg_match("/{$key}(\\d+)$/", $user, $match) && isset($match[1])) {
$userIds[] = $match[1];
}
}
Expand Down
3 changes: 2 additions & 1 deletion common/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
*/
use App\Setting\Service\SettingConfigService;
use App\System\Vo\AmqpQueueVo;
use App\System\Vo\QueueMessageVo;
use Hyperf\Cache\Listener\DeleteListenerEvent;
use Hyperf\Context\ApplicationContext;
Expand Down Expand Up @@ -100,7 +101,7 @@ function push_queue_message(QueueMessageVo $message, array $receiveUsers = []):
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
function add_queue(App\System\Vo\AmqpQueueVo $amqpQueueVo): bool
function add_queue(AmqpQueueVo $amqpQueueVo): bool
{
return container()
->get(QueueLogServiceInterface::class)
Expand Down
19 changes: 11 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
"description": "Quickly build a background management system for web applications",
"license": "Apache-2.0",
"require": {
"xmo/jwt-auth": "2.0.0-alpha.4",
"xmo/mine-core": "2.0.0-alpha.4",
"xmo/mine-helpers": "2.0.0-alpha.4",
"xmo/mine-office": "2.0.0-alpha.4",
"xmo/mine-translatable": "2.0.0-alpha.4",
"xmo/mine-generator": "2.0.0-alpha.4",
"xmo/mine-service": "2.0.0-alpha.4"
"xmo/jwt-auth": "2.0.0-beta",
"xmo/mine-core": "2.0.0-beta",
"xmo/mine-helpers": "2.0.0-beta",
"xmo/mine-office": "^1.5",
"xmo/mine-translatable": "2.0.0-beta",
"xmo/mine-generator": "2.0.0-beta",
"xmo/mine-service": "2.0.0-beta"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
Expand All @@ -40,7 +40,10 @@
"App\\": "app/",
"Api\\": "api/",
"Plugin\\": "plugin/"
}
},
"files": [
"common/common.php"
]
},
"autoload-dev": {
"psr-4": {
Expand Down
Loading

0 comments on commit 05cffdf

Please sign in to comment.