Tencent / APIJSON

🏆 实时 零代码、全功能、强安全 ORM 库 🚀 后端接口和文档零代码,前端(客户端) 定制返回 JSON 的数据和结构 🏆 Real-Time coding-free, powerful and secure ORM 🚀 providing APIs and Docs without coding by Backend, and the returned JSON of API can be customized by Frontend(Client) users
http://apijson.cn
Other
17.16k stars 2.15k forks source link

[权限] ACCESS的时候,只查询前100条,现在表里面超过100条无法查询 #581

Open tanfen100 opened 1 year ago

tanfen100 commented 1 year ago

Description

权限查询ACCESS的时候,只查询前100条,现在表里面超过100条无法查到,导致权限无法生效

TommyLemon commented 1 year ago

DemoParser 重写 getMaxQueryCount,具体看常见问题

cloudAndMonkey commented 1 year ago

apijson 支持增量加载.自己可以扩展, 参见示例如下代码:

int eveNum = 1;
while (true) {
    JSONObject table = new JSONObject();
    table.put("id{}", ">=" + (30 * eveNum));
    table.setOrder("id+");
    APIJSONVerifier.initAccess(IS_INIT_SHUTDOWNWHENSERVERERROR, 
        APIJSONApplication.DEFAULT_APIJSON_CREATOR, table);
    int tmp_accessMapCount = AbstractVerifier.getAccessSize();
    if (accessMapCount == tmp_accessMapCount) {
        break;
    } else {
        accessMapCount = tmp_accessMapCount;
    }
    eveNum++;
}
TommyLemon commented 1 year ago

apijson 支持增量加载.自己可以扩展, 参见示例如下代码:

int eveNum = 1;
while (true) {
  JSONObject table = new JSONObject();
  table.put("id{}", ">=" + (30 * eveNum));
  table.setOrder("id+");
  APIJSONVerifier.initAccess(IS_INIT_SHUTDOWNWHENSERVERERROR, 
        APIJSONApplication.DEFAULT_APIJSON_CREATOR, table);
  int tmp_accessMapCount = AbstractVerifier.getAccessSize();
  if (accessMapCount == tmp_accessMapCount) {
      break;
  } else {
      accessMapCount = tmp_accessMapCount;
  }
  eveNum++;
}

这样更好,不会把业务表查询限制放得很开

TommyLemon commented 1 year ago

其实之前已经针对 APIJSON 配置表,用 SQLConfig.limitCount 做了不设置查询上限数量的处理 https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L847-L850 image

https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java#L174-L196 image

但因为 APIJSONVerifier.initAccess 中 accessItem.toArray(0, 0, ACCESS_) 传参 0 导致只能按 Parser.getMaxQueryCount 返回的最大数量查询
https://github.com/APIJSON/apijson-framework/blob/master/src/main/java/apijson/framework/APIJSONVerifier.java#L168-L171 image

所以需要改为 accessItem.toArray(null, 0, ACCESS_),但因为这个方法参数类型为 int 不能传 null,所以也需要把 int 改为 Integer,最好 int count, int page 都改为 Integer https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/JSONRequest.java#L164-L180

Screenshot 2023-07-30 at 23 45 32

改了后麻烦提交 PR 贡献代码,开源要大家一起参与贡献才会更美好~ image https://github.com/Tencent/APIJSON/blob/master/CONTRIBUTING.md