mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 规则全面缓存,提升Api请求速度
This commit is contained in:
parent
839a403f24
commit
7141eac9bb
@ -30,6 +30,7 @@ class ApiManageController extends BaseController {
|
|||||||
$data = I('post.');
|
$data = I('post.');
|
||||||
$res = D('ApiList')->where(array('id' => $data['id']))->save($data);
|
$res = D('ApiList')->where(array('id' => $data['id']))->save($data);
|
||||||
if( $res === false ) {
|
if( $res === false ) {
|
||||||
|
S('ApiInfo_' . $data['hash'], 0);
|
||||||
$this->ajaxError('操作失败');
|
$this->ajaxError('操作失败');
|
||||||
} else {
|
} else {
|
||||||
$this->ajaxSuccess('添加成功');
|
$this->ajaxSuccess('添加成功');
|
||||||
@ -57,6 +58,8 @@ class ApiManageController extends BaseController {
|
|||||||
if( IS_POST ) {
|
if( IS_POST ) {
|
||||||
$id = I('post.id');
|
$id = I('post.id');
|
||||||
if( $id ) {
|
if( $id ) {
|
||||||
|
$hash = D('ApiList')->where(array('id' => $id))->getField('hash');
|
||||||
|
S('ApiInfo_' . $hash, 0);
|
||||||
D('ApiList')->open(array('id' => $id));
|
D('ApiList')->open(array('id' => $id));
|
||||||
$this->ajaxSuccess('操作成功');
|
$this->ajaxSuccess('操作成功');
|
||||||
} else {
|
} else {
|
||||||
@ -69,6 +72,8 @@ class ApiManageController extends BaseController {
|
|||||||
if( IS_POST ) {
|
if( IS_POST ) {
|
||||||
$id = I('post.id');
|
$id = I('post.id');
|
||||||
if( $id ) {
|
if( $id ) {
|
||||||
|
$hash = D('ApiList')->where(array('id' => $id))->getField('hash');
|
||||||
|
S('ApiInfo_' . $hash, 0);
|
||||||
D('ApiList')->close(array('id' => $id));
|
D('ApiList')->close(array('id' => $id));
|
||||||
$this->ajaxSuccess('操作成功');
|
$this->ajaxSuccess('操作成功');
|
||||||
} else {
|
} else {
|
||||||
@ -81,6 +86,8 @@ class ApiManageController extends BaseController {
|
|||||||
if( IS_POST ) {
|
if( IS_POST ) {
|
||||||
$id = I('post.id');
|
$id = I('post.id');
|
||||||
if( $id ) {
|
if( $id ) {
|
||||||
|
$hash = D('ApiList')->where(array('id' => $id))->getField('hash');
|
||||||
|
S('ApiInfo_' . $hash, 0);
|
||||||
D('ApiList')->del(array('id' => $id));
|
D('ApiList')->del(array('id' => $id));
|
||||||
$this->ajaxSuccess('操作成功');
|
$this->ajaxSuccess('操作成功');
|
||||||
} else {
|
} else {
|
||||||
|
@ -77,6 +77,11 @@ class FieldsManageController extends BaseController {
|
|||||||
if ($res === false) {
|
if ($res === false) {
|
||||||
$this->ajaxError('操作失败');
|
$this->ajaxError('操作失败');
|
||||||
} else {
|
} else {
|
||||||
|
if ($data['type'] == 0) {
|
||||||
|
S('ApiRequest_' . $data['hash'], 0);
|
||||||
|
} else {
|
||||||
|
S('ApiResponse_' . $data['hash'], 0);
|
||||||
|
}
|
||||||
$this->ajaxSuccess('添加成功');
|
$this->ajaxSuccess('添加成功');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -94,6 +99,12 @@ class FieldsManageController extends BaseController {
|
|||||||
if (IS_POST) {
|
if (IS_POST) {
|
||||||
$id = I('post.id');
|
$id = I('post.id');
|
||||||
if ($id) {
|
if ($id) {
|
||||||
|
$detail = D('ApiFields')->where(array('id' => $id))->find();
|
||||||
|
if ($detail['type'] == 0) {
|
||||||
|
S('ApiRequest_' . $detail['hash'], 0);
|
||||||
|
} else {
|
||||||
|
S('ApiResponse_' . $detail['hash'], 0);
|
||||||
|
}
|
||||||
D('ApiFields')->where(array('id' => $id))->delete();
|
D('ApiFields')->where(array('id' => $id))->delete();
|
||||||
$this->ajaxSuccess('操作成功');
|
$this->ajaxSuccess('操作成功');
|
||||||
} else {
|
} else {
|
||||||
@ -105,6 +116,7 @@ class FieldsManageController extends BaseController {
|
|||||||
public function upload() {
|
public function upload() {
|
||||||
if (IS_POST) {
|
if (IS_POST) {
|
||||||
$hash = I('post.hash');
|
$hash = I('post.hash');
|
||||||
|
$type = I('post.type');
|
||||||
$jsonStr = I('post.jsonStr');
|
$jsonStr = I('post.jsonStr');
|
||||||
$jsonStr = html_entity_decode($jsonStr);
|
$jsonStr = html_entity_decode($jsonStr);
|
||||||
$data = json_decode($jsonStr, true);
|
$data = json_decode($jsonStr, true);
|
||||||
@ -112,7 +124,7 @@ class FieldsManageController extends BaseController {
|
|||||||
$this->handle($data['data'], $dataArr);
|
$this->handle($data['data'], $dataArr);
|
||||||
$old = D('ApiFields')->where(array(
|
$old = D('ApiFields')->where(array(
|
||||||
'hash' => $hash,
|
'hash' => $hash,
|
||||||
'type' => I('post.type')
|
'type' => $type
|
||||||
))->select();
|
))->select();
|
||||||
$oldArr = array_column($old, 'showName');
|
$oldArr = array_column($old, 'showName');
|
||||||
$newArr = array_column($dataArr, 'showName');
|
$newArr = array_column($dataArr, 'showName');
|
||||||
@ -130,6 +142,12 @@ class FieldsManageController extends BaseController {
|
|||||||
}
|
}
|
||||||
D('ApiFields')->addAll($addData);
|
D('ApiFields')->addAll($addData);
|
||||||
}
|
}
|
||||||
|
if ($type) {
|
||||||
|
S('ApiRequest_' . $hash, 0);
|
||||||
|
} else {
|
||||||
|
S('ApiResponse_' . $hash, 0);
|
||||||
|
}
|
||||||
|
S('ApiReturnType_' . $hash, 0);
|
||||||
$this->ajaxSuccess('操作成功');
|
$this->ajaxSuccess('操作成功');
|
||||||
} else {
|
} else {
|
||||||
$this->display();
|
$this->display();
|
||||||
|
@ -25,16 +25,42 @@ class ApiController extends BaseController {
|
|||||||
public function index() {
|
public function index() {
|
||||||
$getArr = I('get.');
|
$getArr = I('get.');
|
||||||
$postArr = I('post.');
|
$postArr = I('post.');
|
||||||
$this->apiDetail = M('ApiList')->where(array('hash' => $getArr['hash'], 'status' => 1))->find();
|
|
||||||
|
//获取ApiInfo根据
|
||||||
|
$this->apiDetail = S('ApiInfo_' . $getArr['hash']);
|
||||||
|
if (!$this->apiDetail) {
|
||||||
|
$this->apiDetail = M('ApiList')->where(array('hash' => $getArr['hash'], 'status' => 1))->find();
|
||||||
|
S('ApiInfo_' . $getArr['hash'], json_encode($this->apiDetail));
|
||||||
|
} else {
|
||||||
|
$this->apiDetail = json_decode($this->apiDetail, true);
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($this->apiDetail)) {
|
if (empty($this->apiDetail)) {
|
||||||
Response::error(ReturnCode::NOT_EXISTS, '非法的API标识');
|
Response::error(ReturnCode::NOT_EXISTS, '非法的API标识');
|
||||||
}
|
}
|
||||||
ApiLog::setApiInfo($this->apiDetail);
|
ApiLog::setApiInfo($this->apiDetail);
|
||||||
|
|
||||||
$this->apiRequest = M('ApiFields')->where(array('hash' => $getArr['hash'], 'type' => 0))->select();
|
$this->apiRequest = S('ApiRequest_' . $getArr['hash']);
|
||||||
$this->apiResponse = M('ApiFields')->where(array('hash' => $getArr['hash'], 'type' => 1))->select();
|
if (!$this->apiRequest) {
|
||||||
$returnType = M('ApiFields')->where(array('hash' => $getArr['hash'], 'showName' => 'data', 'type' => 1))->find();
|
$this->apiRequest = M('ApiFields')->where(array('hash' => $getArr['hash'], 'type' => 0))->select();
|
||||||
|
S('ApiRequest_' . $getArr['hash'], json_encode($this->apiRequest));
|
||||||
|
} else {
|
||||||
|
$this->apiRequest = json_decode($this->apiRequest, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->apiResponse = S('ApiResponse_' . $getArr['hash']);
|
||||||
|
if (!$this->apiResponse) {
|
||||||
|
$this->apiResponse = M('ApiFields')->where(array('hash' => $getArr['hash'], 'type' => 1))->select();
|
||||||
|
S('ApiResponse_' . $getArr['hash'], json_encode($this->apiResponse));
|
||||||
|
} else {
|
||||||
|
$this->apiResponse = json_decode($this->apiResponse, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$returnType = S('ApiReturnType_' . $getArr['hash']);
|
||||||
|
if (!$returnType) {
|
||||||
|
$returnType = M('ApiFields')->where(array('hash' => $getArr['hash'], 'showName' => 'data', 'type' => 1))->getField('dataType');
|
||||||
|
S('ApiReturnType_' . $getArr['hash'], $returnType);
|
||||||
|
}
|
||||||
Response::setDataType($returnType['dataType']);
|
Response::setDataType($returnType['dataType']);
|
||||||
|
|
||||||
$this->header = apache_request_headers();
|
$this->header = apache_request_headers();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user