Skip to content

feat(ip-region): support IPDB alongside ip2region - #1203

Merged
qwqcode merged 2 commits into
masterfrom
codex/fix-ip-region-precision
Oct 28, 2026
Merged

qwqcode merged 2 commits into
masterfrom
codex/fix-ip-region-precision

Conversation

@qwqcode

@qwqcode qwqcode commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Add standard IPDB geolocation databases alongside the existing ip2region XDB support. Users can point the existing ip_region.db_path at a qqwry standard .ipdb file to cover IPv4 and IPv6 with one database. XDB remains the default, including legacy filenames without extensions. No new configuration keys, API fields, or database migrations are required.

Both readers return country, province, and city fields to one precision formatter. This also fixes the current ip2region layout being read as the legacy layout: precision: province previously displayed 福州 instead of 福建, while city precision could include the ISP. Missing provinces fall back to the country without exposing the city.

Readers are cached per configured client instead of a process-wide singleton. Path, precision, or cache-setting changes replace the client, and service reinitialization releases the old cache. Cached XDB access is synchronized because the upstream searcher mutates its IO counter. Failed loads can retry; corrupt database offsets cannot panic a comment request. The IPDB reader uses the upstream ipipdotnet/ipdb-go library and reads fields by name, preferring CN and falling back to EN.

Documentation includes both download options and the memory tradeoff: IPDB loads the whole file, so cache.enabled: true is recommended; disabling caching reloads it for each query. The raw qqwry edition is not suitable for these precision settings.

Fixes #1175. Addresses the IPv6/database-format use case discussed in #782.

Validation:

  • go test ./...
  • go vet ./...
  • go test -race ./internal/ip_region ./internal/core -count=1
  • pnpm build:docs and Prettier checks on changed documentation/configuration files
  • Generated local fixtures cover legacy/current XDB, IPv6 XDB, dual-stack IPDB, reordered fields, precision fallbacks, invalid metadata, corrupt offsets, cache isolation, concurrent queries, failed-load recovery, configuration changes, and service reinitialization. CI does not download geolocation databases.
  • Real queries against qqwry.ipdb 2026.10.21 for IPv4 and IPv6, with all precision levels and cache on/off; legacy/current IPv4 and current IPv6 XDB files also pass.
  • The precision fix was additionally checked against 683,591 legacy and 516,860 current upstream IPv4 records.

Browser validation in an isolated localhost instance using the current backend and real published databases: submitted three comments with controlled IPv4/IPv6 source IPs, verified persistence after refresh, and exercised eight database/precision/cache combinations (IPDB province/city/country, cache off, current/legacy IPv4 XDB, and IPv6 XDB). All 123 captured API responses were HTTP 200; the browser console had no errors or warnings. The rendered documentation was also checked.

@qwqcode qwqcode changed the title fix(ip-region): preserve precision with current ip2region databases feat(ip-region): support IPDB alongside ip2region Oct 28, 2026
@qwqcode
qwqcode merged commit 4d54940 into master Oct 28, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IP属地的精度为province,但是实际显示到了city

1 participant