Skip to content

fix: add rate limiting to DingTalk org sync API calls#374

Merged
wisdomqin merged 1 commit intodataelement:mainfrom
39499740:fix/dingtalk-org-sync-rate-limit
Apr 12, 2026
Merged

fix: add rate limiting to DingTalk org sync API calls#374
wisdomqin merged 1 commit intodataelement:mainfrom
39499740:fix/dingtalk-org-sync-rate-limit

Conversation

@39499740
Copy link
Copy Markdown
Contributor

@39499740 39499740 commented Apr 10, 2026

Summary

Add request throttling to DingTalkOrgSyncAdapter to prevent hitting DingTalk's API rate limit (~20 QPS per interface per app).

The fetch_departments() and fetch_users() methods were issuing HTTP requests in tight loops without any delay, causing QPS throttle errors (subcode=90018) when syncing organizations with many departments.

Changes:

  • Add 60ms delay (asyncio.sleep(0.06)) between consecutive API calls in both fetch_departments() and fetch_users(), keeping the rate at ~16 QPS
  • Move asyncio import to module level (was locally imported in FeishuOrgSyncAdapter)
  • Consistent with FeishuOrgSyncAdapter which already uses Semaphore(15) for rate limiting

Fixes #373

Checklist

  • Tested locally
  • No unrelated changes included

DingTalk enforces ~20 QPS per app per API interface. The
DingTalkOrgSyncAdapter was issuing requests in tight loops without
any delay, causing QPS throttle errors (subcode=90018) during org
sync for organizations with many departments.

- Add 60ms delay between requests in fetch_departments() and
  fetch_users() to stay safely under the 20 QPS limit
- Move asyncio import to module level (was locally imported in
  FeishuOrgSyncAdapter)
- Consistent with FeishuOrgSyncAdapter which already uses
  Semaphore(15) for rate limiting

Fixes dataelement#373
@wisdomqin
Copy link
Copy Markdown
Contributor

Thanks for the fix! 🎉 Cherry-picked to bugfix branch (558dd8c). Will be included in the next release.

@wisdomqin wisdomqin closed this Apr 12, 2026
@wisdomqin wisdomqin reopened this Apr 12, 2026
@wisdomqin wisdomqin merged commit 2dd3d02 into dataelement:main Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DingTalk org sync triggers API rate limiting (QPS throttle)

2 participants