From d9ab61437240738c1034888be0f76706010dda4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=81=E7=81=AB=E8=A1=8C=E8=80=85?= Date: Thu, 14 Oct 2021 19:21:14 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=88=A0=E9=99=A4hMGetCollection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Base/DzqCache.php | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/src/Base/DzqCache.php b/src/Base/DzqCache.php index d8b5c73..b1679af 100644 --- a/src/Base/DzqCache.php +++ b/src/Base/DzqCache.php @@ -196,41 +196,6 @@ class DzqCache return $ret; } - /** - * @desc 附件数据获取 - * todo 后续去除模型传递,废除该方法 - * @param $key - * @param array $hashKeys - * @param callable|null $callBack - * @return bool|Collection - */ - public static function hMGetCollection($key, array $hashKeys, callable $callBack = null) - { - $data = self::getAppCache($key, $hasCache, $cacheData); - $ret = false; - if ($data && self::CACHE_SWICH) { - $ret = new Collection(); - foreach ($hashKeys as $hashKey) { - if (!empty($data[$hashKey])) { - $ret->put($hashKey, $data[$hashKey]); - } else { - $ret = false; - break; - } - } - } - if (($ret === false || !$data) && !empty($callBack)) { - $ret = $callBack($hashKeys); - !$data && $data = new Collection(); - foreach ($ret as $k => $v) { - $data->put($k, $v); - } - $hasCache && self::setAppCache($key, $data, $cacheData); - self::set($key, $data); - } - return $ret; - } - /** * @desc 帖子列表二级缓存和预加载 * @param $key -- Gitee From 87be99c4800d617e758d72da60028ec925148608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=81=E7=81=AB=E8=A1=8C=E8=80=85?= Date: Thu, 14 Oct 2021 19:23:13 +0800 Subject: [PATCH 2/6] no message --- src/Base/DzqCache.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Base/DzqCache.php b/src/Base/DzqCache.php index b1679af..83d8313 100644 --- a/src/Base/DzqCache.php +++ b/src/Base/DzqCache.php @@ -19,7 +19,6 @@ namespace Discuz\Base; use App\Common\CacheKey; -use Illuminate\Database\Eloquent\Collection; class DzqCache { -- Gitee From 04cb34b4ca771371bff7f20a09e3e8d8e46f2850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=81=E7=81=AB=E8=A1=8C=E8=80=85?= Date: Wed, 20 Oct 2021 19:47:19 +0800 Subject: [PATCH 3/6] no message --- src/Base/DzqController.php | 7 ++++--- src/Common/Utils.php | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Base/DzqController.php b/src/Base/DzqController.php index 9c09ca7..6e29f5a 100644 --- a/src/Base/DzqController.php +++ b/src/Base/DzqController.php @@ -231,7 +231,7 @@ abstract class DzqController implements RequestHandlerInterface ]; } - public function preloadPaginiation($pageCount, $perPage, \Illuminate\Database\Eloquent\Builder $builder) + public function preloadPaginiation($currentPage,$pageCount, $perPage, \Illuminate\Database\Eloquent\Builder $builder) { $perPage = $perPage >= 1 ? intval($perPage) : 20; $perPageMax = 50; @@ -239,16 +239,17 @@ abstract class DzqController implements RequestHandlerInterface $count = $builder->count(); $builder = $builder->offset(0)->limit($pageCount * $perPage)->get(); $builder = $builder->toArray(); + dd($builder); $url = $this->request->getUri(); $port = $url->getPort(); $port = $port == null ? '' : ':' . $port; parse_str($url->getQuery(), $query); unset($query['preload']); $ret = []; - $currentPage = 1; $totalCount = $count; $totalPage = $count % $perPage == 0 ? $count / $perPage : intval($count / $perPage) + 1; - while ($currentPage <= $pageCount) { + $limitPage = $currentPage + $pageCount; + while ($currentPage <= $limitPage) { $queryFirst = $queryNext = $queryPre = $query; $queryFirst['page'] = 1; $queryNext['page'] = $currentPage + 1; diff --git a/src/Common/Utils.php b/src/Common/Utils.php index 3b942ac..532ed6d 100644 --- a/src/Common/Utils.php +++ b/src/Common/Utils.php @@ -362,4 +362,17 @@ class Utils } return true; } + + /** + * @desc 正整数 + * @param $number + * @return bool + */ + public static function isPositiveInteger($number) + { + if ($number > 0 && round($number, 0) == $number) { + return true; + } + return false; + } } -- Gitee From a33c83bde20815210e7f610c086611d7852aa012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=81=E7=81=AB=E8=A1=8C=E8=80=85?= Date: Fri, 22 Oct 2021 11:39:09 +0800 Subject: [PATCH 4/6] no message --- src/Base/DzqCache.php | 4 +++- src/Base/DzqController.php | 29 ++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Base/DzqCache.php b/src/Base/DzqCache.php index 83d8313..7aa5b62 100644 --- a/src/Base/DzqCache.php +++ b/src/Base/DzqCache.php @@ -162,7 +162,7 @@ class DzqCache $ret = self::getFragmentFileStore($key, $hashKeys); } else { $data = self::get($key); - $ret = false; + $ret = []; if ($data && self::CACHE_SWICH) { foreach ($hashKeys as $hashKey) { if (array_key_exists($hashKey, $data)) { @@ -174,6 +174,8 @@ class DzqCache break; } } + }else{ + $ret = false; } } if ($ret === false && !empty($callBack)) { diff --git a/src/Base/DzqController.php b/src/Base/DzqController.php index 6e29f5a..3f160a0 100644 --- a/src/Base/DzqController.php +++ b/src/Base/DzqController.php @@ -69,8 +69,8 @@ abstract class DzqController implements RequestHandlerInterface $this->dzqLogInit(); //临时处理管理端接口权限 $path = $this->request->getUri()->getPath(); - if(stristr($path,'backAdmin') && !stristr($path,'backAdmin/login')){ - if(!$this->user->isAdmin()){ + if (stristr($path, 'backAdmin') && !stristr($path, 'backAdmin/login')) { + if (!$this->user->isAdmin()) { throw new PermissionDeniedException('没有权限'); } } @@ -131,6 +131,7 @@ abstract class DzqController implements RequestHandlerInterface } } } + private function setParamsAlias() { $this->saveParamsAlias = []; @@ -141,18 +142,19 @@ abstract class DzqController implements RequestHandlerInterface } } } + /* * 接口入参 */ - public function inPut($name='', $checkValid = true) + public function inPut($name = '', $checkValid = true) { - if(!empty($this->saveParamsAlias[$name])){ + if (!empty($this->saveParamsAlias[$name])) { return $this->saveParamsAlias[$name]; } - if(empty($name)){ - if($this->parseBody instanceof \Illuminate\Support\Collection){ + if (empty($name)) { + if ($this->parseBody instanceof \Illuminate\Support\Collection) { return $this->parseBody->merge($this->queryParams)->all(); - }else{ + } else { return $this->queryParams; } } @@ -231,15 +233,14 @@ abstract class DzqController implements RequestHandlerInterface ]; } - public function preloadPaginiation($currentPage,$pageCount, $perPage, \Illuminate\Database\Eloquent\Builder $builder) + public function preloadPaginiation($currentPage, $pageCount, $perPage, \Illuminate\Database\Eloquent\Builder $builder) { $perPage = $perPage >= 1 ? intval($perPage) : 20; $perPageMax = 50; $perPage > $perPageMax && $perPage = $perPageMax; $count = $builder->count(); - $builder = $builder->offset(0)->limit($pageCount * $perPage)->get(); + $builder = $builder->offset(($currentPage-1)*$perPage)->limit($pageCount * $perPage)->get(); $builder = $builder->toArray(); - dd($builder); $url = $this->request->getUri(); $port = $url->getPort(); $port = $port == null ? '' : ':' . $port; @@ -249,13 +250,14 @@ abstract class DzqController implements RequestHandlerInterface $totalCount = $count; $totalPage = $count % $perPage == 0 ? $count / $perPage : intval($count / $perPage) + 1; $limitPage = $currentPage + $pageCount; - while ($currentPage <= $limitPage) { + $offset = 0; + while ($currentPage < $limitPage) { $queryFirst = $queryNext = $queryPre = $query; - $queryFirst['page'] = 1; + $queryFirst['page'] = $currentPage; $queryNext['page'] = $currentPage + 1; $queryPre['page'] = $currentPage <= 1 ? 1 : $currentPage - 1; $path = $url->getScheme() . '://' . $url->getHost() . $port . $url->getPath() . '?'; - $pageData = (array)array_slice($builder, ($currentPage - 1) * $perPage, $perPage); + $pageData = (array)array_slice($builder, $offset * $perPage, $perPage); $ret[$currentPage] = [ 'pageData' => $pageData, 'currentPage' => $currentPage, @@ -270,6 +272,7 @@ abstract class DzqController implements RequestHandlerInterface if (empty($pageData)) { break; } + $offset++; $currentPage++; } return $ret; -- Gitee From b90a217503aa6824792d905b7170362a04e4751a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=81=E7=81=AB=E8=A1=8C=E8=80=85?= Date: Tue, 26 Oct 2021 15:30:16 +0800 Subject: [PATCH 5/6] cache v3.1 --- src/Base/DzqCache.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Base/DzqCache.php b/src/Base/DzqCache.php index 7aa5b62..cb7e714 100644 --- a/src/Base/DzqCache.php +++ b/src/Base/DzqCache.php @@ -151,12 +151,12 @@ class DzqCache * @param $key * @param $hashKeys * @param callable|null $callBack - * @param null $indexField 数据转换的字段 + * @param null $index 数据转换的字段 * @param bool $mutiColumn 每个字段下的数据是否保留多个 * @param bool $autoCache * @return bool|array */ - public static function hMGet($key, $hashKeys, callable $callBack = null, $indexField = null, $mutiColumn = false, $autoCache = true) + public static function hMGet($key, $hashKeys, callable $callBack = null, $index = null, $mutiColumn = false, $autoCache = true) { if (isset(CacheKey::$fileStore[$key])) { $ret = self::getFragmentFileStore($key, $hashKeys); @@ -180,7 +180,7 @@ class DzqCache } if ($ret === false && !empty($callBack)) { $ret = $callBack($hashKeys); - list($resultWithNull, $resultNotNull) = self::hMSetResult($ret, $indexField, $mutiColumn, $hashKeys, null); + list($resultWithNull, $resultNotNull) = self::hMSetResult($ret, $index, $mutiColumn, $hashKeys, null); if ($autoCache) { if (isset(CacheKey::$fileStore[$key])) { self::putFragmentFileStore($key, $resultWithNull); -- Gitee From 15f7c6e4c91b1d9d090e1e0503eb928cf290d65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=81=E7=81=AB=E8=A1=8C=E8=80=85?= Date: Tue, 26 Oct 2021 20:47:13 +0800 Subject: [PATCH 6/6] no message --- src/Base/DzqCache.php | 44 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/src/Base/DzqCache.php b/src/Base/DzqCache.php index cb7e714..eb6f7f5 100644 --- a/src/Base/DzqCache.php +++ b/src/Base/DzqCache.php @@ -64,28 +64,6 @@ class DzqCache return true; } - public static function hSet($key, $hashKey, $value) - { - $data = self::get($key); - $data[$hashKey] = $value; - return self::set($key, $data); - } - - public static function hMSet($key, array $value, $indexField = null, $mutiColumn = false, $indexes = [], $defaultValue = []) - { - list($result) = self::hMSetResult($value, $indexField, $mutiColumn, $indexes, $defaultValue); - if (isset(CacheKey::$fileStore[$key])) { - self::putFragmentFileStore($key, $result); - } else { - $data = self::get($key); - foreach ($result as $k => $v) { - $data[$k] = $v; - } - self::set($key, $data); - } - return $result; - } - /** * @desc 获取一个key下的数据 * @param $key @@ -163,19 +141,21 @@ class DzqCache } else { $data = self::get($key); $ret = []; - if ($data && self::CACHE_SWICH) { - foreach ($hashKeys as $hashKey) { - if (array_key_exists($hashKey, $data)) { - if (!empty($data[$hashKey])) { - $ret[$hashKey] = $data[$hashKey]; + if(!empty($hashKeys)){ + if ($data && self::CACHE_SWICH) { + foreach ($hashKeys as $hashKey) { + if (array_key_exists($hashKey, $data)) { + if (!empty($data[$hashKey])) { + $ret[$hashKey] = $data[$hashKey]; + } + } else { + $ret = false; + break; } - } else { - $ret = false; - break; } + }else{ + $ret = false; } - }else{ - $ret = false; } } if ($ret === false && !empty($callBack)) { -- Gitee