GrouchyAdmin |
06-14-2008 09:53 AM |
Quote:
Originally Posted by elron
(Post 14319419)
I've bought Power Redirector and it looks like im gonna cancel the transaction , it works fine if u need to redirect just one or two countries , but if u have like 30 (in my case) it hits the sql DB 30 times and searches over the entire ip list each time , and that causes serious SQL overload .
|
Haha. Wow.
This is the problem you find when people who aren't very seasoned decide to make software, and design it entirely wrong. The smartest move would be to convert the dotted quad to a long, and run a binary search on it from the prepopulated tables.
Something like:
Code:
BinarySearch(A[0..N-1], ip) {
low = 0
high = N - 1
while (low <= high) {
mid = (low + high) / 2
if (ip <= A[mid].EndIp) {
if (ip >= A[mid].StartIp) {
return true;
} else {
high = mid - 1;
}
} else {
low = mid + 1
}
}
return false
}
Would be at least O(log n), which is going to be as good as you can do with MySQL, anyhow.
.. or, you could install mod_geoip2, and get the country code with every request, then do the world's lamest switch statement. It'd still be faster.
|