Faster geoip in most cases

This commit is contained in:
What.CD 2011-05-01 08:00:05 +00:00
parent 3b0f7f967a
commit bb9600894d
2 changed files with 7 additions and 4 deletions

View File

@ -424,12 +424,14 @@ function geoip($IP) {
return $IPs[$IP];
}
$Long = ip2unsigned($IP);
if($Long == 2130706433 || !$Long) {
if(!$Long || $Long == 2130706433) { // No need to check cc for 127.0.0.1
return false;
}
global $DB;
$DB->query("SELECT Code FROM geoip_country WHERE $Long BETWEEN StartIP AND EndIP LIMIT 1");
list($Country) = $DB->next_record();
$DB->query("SELECT EndIP,Code FROM geoip_country WHERE $Long >= StartIP ORDER BY StartIP DESC LIMIT 1");
if((!list($EndIP,$Country) = $DB->next_record()) || $EndIP < $Long) {
$Country = '?';
}
$IPs[$IP] = $Country;
return $Country;
}

View File

@ -339,7 +339,8 @@ CREATE TABLE `ip_bans` (
`Reason` varchar(255) DEFAULT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `FromIP_2` (`FromIP`,`ToIP`),
KEY `FromIP` (`FromIP`,`ToIP`)
KEY `FromIP` (`FromIP`,`ToIP`),
KEY `ToIP` (`ToIP`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `log` (