Skip to content

Commit

Permalink
Adds indexes to the netblock table (#2780)
Browse files Browse the repository at this point in the history
Netblock is really big, so adding some indexes to the decimal IP fields
(used to do the actual locating) to speed things up.
  • Loading branch information
jkachel authored Oct 2, 2023
1 parent 1b8dd7f commit d4684ef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
31 changes: 31 additions & 0 deletions maxmind/migrations/0002_add_indexes_to_decimal_ips.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 3.2.21 on 2023-10-02 14:37

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("maxmind", "0001_add_geoname_and_netblock_tables"),
]

operations = [
migrations.AddIndex(
model_name="netblock",
index=models.Index(
fields=["decimal_ip_start"], name="maxmind_net_decimal_dfdb1a_idx"
),
),
migrations.AddIndex(
model_name="netblock",
index=models.Index(
fields=["decimal_ip_end"], name="maxmind_net_decimal_6166c4_idx"
),
),
migrations.AddIndex(
model_name="netblock",
index=models.Index(
fields=["decimal_ip_start", "decimal_ip_end"],
name="maxmind_net_decimal_ab7249_idx",
),
),
]
5 changes: 5 additions & 0 deletions maxmind/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ class Meta:
name="at_least_one_geoname_id",
)
]
indexes = [
models.Index(fields=["decimal_ip_start"]),
models.Index(fields=["decimal_ip_end"]),
models.Index(fields=["decimal_ip_start", "decimal_ip_end"]),
]

def __str__(self):
return f"{self.geoname_id}: {self.network} (IPv6 {self.is_ipv6}) start {self.ip_start} end {self.ip_end}"

0 comments on commit d4684ef

Please sign in to comment.