Merge pull request #77 from Cerberus98/moar_indices
More optimizations and indexes for #75
This commit is contained in:
@@ -267,7 +267,7 @@ def mac_address_range_find_allocation_counts(context, address=None):
|
|||||||
sql_func.count(models.MacAddress.address).
|
sql_func.count(models.MacAddress.address).
|
||||||
label("count")).with_lockmode("update")
|
label("count")).with_lockmode("update")
|
||||||
query = query.outerjoin(models.MacAddress)
|
query = query.outerjoin(models.MacAddress)
|
||||||
query = query.group_by(models.MacAddressRange)
|
query = query.group_by(models.MacAddressRange.id)
|
||||||
query = query.order_by("count DESC")
|
query = query.order_by("count DESC")
|
||||||
if address:
|
if address:
|
||||||
query = query.filter(models.MacAddressRange.last_address >= address)
|
query = query.filter(models.MacAddressRange.last_address >= address)
|
||||||
|
|||||||
@@ -119,14 +119,14 @@ class IPAddress(BASEV2, models.HasId):
|
|||||||
"""
|
"""
|
||||||
__tablename__ = "quark_ip_addresses"
|
__tablename__ = "quark_ip_addresses"
|
||||||
address_readable = sa.Column(sa.String(128), nullable=False)
|
address_readable = sa.Column(sa.String(128), nullable=False)
|
||||||
address = sa.Column(custom_types.INET(), nullable=False)
|
address = sa.Column(custom_types.INET(), nullable=False, index=True)
|
||||||
subnet_id = sa.Column(sa.String(36),
|
subnet_id = sa.Column(sa.String(36),
|
||||||
sa.ForeignKey("quark_subnets.id",
|
sa.ForeignKey("quark_subnets.id",
|
||||||
ondelete="CASCADE"))
|
ondelete="CASCADE"))
|
||||||
network_id = sa.Column(sa.String(36),
|
network_id = sa.Column(sa.String(36),
|
||||||
sa.ForeignKey("quark_networks.id",
|
sa.ForeignKey("quark_networks.id",
|
||||||
ondelete="CASCADE"))
|
ondelete="CASCADE"))
|
||||||
version = sa.Column(sa.Integer())
|
version = sa.Column(sa.Integer(), index=True)
|
||||||
allocated_at = sa.Column(sa.DateTime())
|
allocated_at = sa.Column(sa.DateTime())
|
||||||
subnet = orm.relationship("Subnet", lazy="joined")
|
subnet = orm.relationship("Subnet", lazy="joined")
|
||||||
# Need a constant to facilitate the indexed search for new IPs
|
# Need a constant to facilitate the indexed search for new IPs
|
||||||
@@ -157,7 +157,7 @@ class IPAddress(BASEV2, models.HasId):
|
|||||||
return str(ip.ipv4())
|
return str(ip.ipv4())
|
||||||
return str(ip.ipv6())
|
return str(ip.ipv6())
|
||||||
|
|
||||||
deallocated_at = sa.Column(sa.DateTime())
|
deallocated_at = sa.Column(sa.DateTime(), index=True)
|
||||||
|
|
||||||
|
|
||||||
class Route(BASEV2, models.HasTenant, models.HasId, IsHazTags):
|
class Route(BASEV2, models.HasTenant, models.HasId, IsHazTags):
|
||||||
|
|||||||
@@ -156,7 +156,6 @@ def get_network(context, id, fields=None):
|
|||||||
(id, context.tenant_id, fields))
|
(id, context.tenant_id, fields))
|
||||||
|
|
||||||
network = db_api.network_find(context, id=id, scope=db_api.ONE)
|
network = db_api.network_find(context, id=id, scope=db_api.ONE)
|
||||||
|
|
||||||
if not network:
|
if not network:
|
||||||
raise exceptions.NetworkNotFound(net_id=id)
|
raise exceptions.NetworkNotFound(net_id=id)
|
||||||
return v._make_network_dict(network)
|
return v._make_network_dict(network)
|
||||||
|
|||||||
Reference in New Issue
Block a user