Repository navigation
feat(ip-region): support IPDB alongside ip2region - #1203
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add standard IPDB geolocation databases alongside the existing ip2region XDB support. Users can point the existing
ip_region.db_pathat a qqwry standard.ipdbfile 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: provincepreviously 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-golibrary 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: trueis 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=1pnpm build:docsand Prettier checks on changed documentation/configuration filesBrowser 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.