Skip to content

Commit 43c22ab

Browse files
committed
Server:优化性能(优化Array的count)
1 parent 0cfbdcd commit 43c22ab

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

  • APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server

APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/RequestParser.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import com.alibaba.fastjson.JSONObject;
2929

3030
import zuo.biao.apijson.JSON;
31-
import zuo.biao.apijson.JSONRequest;
31+
import zuo.biao.apijson.JSONResponse;
3232
import zuo.biao.apijson.RequestMethod;
3333
import zuo.biao.apijson.StringUtil;
3434
import zuo.biao.apijson.Table;
@@ -555,38 +555,38 @@ private JSONObject getArray(String parentPath, QueryConfig parentConfig, String
555555
System.out.println(TAG + "getArray try { page = arrayObject.getIntValue(page); ..." +
556556
" >> } catch (Exception e) {\n" + e.getMessage());
557557
}
558-
558+
if (count <= 0 || count > 100) {//count最大为100
559+
count = 100;
560+
}
561+
559562
//最好先获取第一个table的所有项(where条件),填充一个列表?
560563
Set<String> set = request.keySet();
561564
if (count <= 0 || count > 10) {//10以下不优化长度
562565
if(parseRelation == false && set != null) {
563-
JSONObject object;
566+
Object object;
564567
int totalCount = 0;
565568
for (String key : set) {
566-
if (isTableKey(key)) {
567-
object = getJSONObject(request, key);
568-
if (object != null) {// && object.isEmpty() == false) {
569-
totalCount = QueryHelper.getInstance().getCount(key);
570-
break;
571-
}
569+
object = isTableKey(key) ? request.get(key) : null;
570+
if (object != null && object instanceof JSONObject) {// && object.isEmpty() == false) {
571+
// totalCount = QueryHelper.getInstance().getCount(key);
572+
JSONObject response = new RequestParser(RequestMethod.HEAD)
573+
.parseResponse(new JSONRequest(key, object));
574+
JSONObject target = response == null ? null : response.getJSONObject(key);
575+
totalCount = target == null ? 0 : target.getIntValue(JSONResponse.KEY_COUNT);
576+
break;
572577
}
573578
}
574579
if (totalCount <= 0) {//request内部没有JSONObject或者不存在适合条件的table内容
575580
return null;
576581
}
577582
if (count > totalCount) {
578583
count = totalCount;
584+
request.put(JSONRequest.KEY_COUNT, count);
579585
}
580586
}
581587
}
582-
if (count <= 0 || count > 100) {//count最大为100
583-
count = 100;
584-
}
585588

586-
// if (parseRelation) {
587-
// request.remove("page");
588-
// request.remove("count");
589-
// }
589+
590590
System.out.println(TAG + "getArray page = " + page + "; count = " + count);
591591

592592
QueryConfig config = new QueryConfig(requestMethod, count, page);
@@ -625,6 +625,9 @@ private JSONObject getArray(String parentPath, QueryConfig parentConfig, String
625625
}
626626
}
627627
} else {
628+
// request.remove(JSONRequest.KEY_PAGE);
629+
// request.remove(JSONRequest.KEY_COUNT);
630+
628631
for (String key : set) {
629632
value = request.get(key);
630633
if (value instanceof JSONObject) {//JSONObject,往下一级提取

0 commit comments

Comments
 (0)