Merged PR 57: Bug 534:アプリ件数100件超える場合、100件しか表示される問題修正

原因:kintone APIは一回取得できるアプリの件数は100件で制限されている
対策:一回取得されたアプリ件数は最大100件の場合、offsetを指定して繰り返し取得するように対応しました。
kintoneのアプリはスタンダードコース最大1000個、ワイドコース最大3000個アプリがありますので、
上記の対策は最大10~30回取得する可能性がありますが、通常は問題がありません。
もしアプリは1000件超えて、性能問題がある場合は、frontend側で改ページするように検討が必要です。

Related work items: #534
This commit is contained in:
Shohtetsu Ma
2024-07-22 09:54:50 +00:00
committed by Takuto Yoshida(タクト)

View File

@@ -516,10 +516,22 @@ async def allapps(request:Request,c:config.KINTONE_ENV=Depends(getkintoneenv)):
try:
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
url = f"{c.BASE_URL}{config.API_V1_STR}/apps.json"
r = httpx.get(url,headers=headers)
return r.json()
offset = 0
limit = 100
all_apps = []
while True:
r = httpx.get(f"{url}?limit={limit}&offset={offset}", headers=headers)
json_data = r.json()
apps = json_data.get("apps",[])
all_apps.extend(apps)
if len(apps)<limit:
break
offset += limit
return {"apps": all_apps}
except Exception as e:
raise APIException('kintone:allapps',request.url._url, f"Error occurred while get allapps({c.DOMAIN_NAME}):",e)
raise APIException('kintone:allapps', request.url._url, f"Error occurred while get allapps({c.DOMAIN_NAME}):", e)
@r.get("/appfields")
async def appfields(request:Request,app:str,env = Depends(getkintoneenv)):