Merge pull request #2797 from castrapel/get_or_increase_name_simplify
Make get_or_increase_name queries less demanding
This commit is contained in:
commit
8bc23f6deb
|
@ -71,21 +71,21 @@ def get_sequence(name):
|
||||||
|
|
||||||
|
|
||||||
def get_or_increase_name(name, serial):
|
def get_or_increase_name(name, serial):
|
||||||
certificates = Certificate.query.filter(
|
certificates = Certificate.query.filter(Certificate.name == name).all()
|
||||||
Certificate.name.ilike("{0}%".format(name))
|
|
||||||
).all()
|
|
||||||
|
|
||||||
if not certificates:
|
if not certificates:
|
||||||
return name
|
return name
|
||||||
|
|
||||||
serial_name = "{0}-{1}".format(name, hex(int(serial))[2:].upper())
|
serial_name = "{0}-{1}".format(name, hex(int(serial))[2:].upper())
|
||||||
certificates = Certificate.query.filter(
|
certificates = Certificate.query.filter(Certificate.name == serial_name).all()
|
||||||
Certificate.name.ilike("{0}%".format(serial_name))
|
|
||||||
).all()
|
|
||||||
|
|
||||||
if not certificates:
|
if not certificates:
|
||||||
return serial_name
|
return serial_name
|
||||||
|
|
||||||
|
certificates = Certificate.query.filter(
|
||||||
|
Certificate.name.ilike("{0}%".format(serial_name))
|
||||||
|
).all()
|
||||||
|
|
||||||
ends = [0]
|
ends = [0]
|
||||||
root, end = get_sequence(serial_name)
|
root, end = get_sequence(serial_name)
|
||||||
for cert in certificates:
|
for cert in certificates:
|
||||||
|
|
|
@ -53,7 +53,8 @@ def test_get_or_increase_name(session, certificate):
|
||||||
== "test-cert-11111111-1-" + serial
|
== "test-cert-11111111-1-" + serial
|
||||||
)
|
)
|
||||||
|
|
||||||
cert2 = CertificateFactory(name="certificate1-" + serial)
|
CertificateFactory(name="certificate1")
|
||||||
|
CertificateFactory(name="certificate1-" + serial)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
assert get_or_increase_name(
|
assert get_or_increase_name(
|
||||||
|
|
Loading…
Reference in New Issue