From b71f2fc5110ef7949d6e72fa7a4db909780c7dcd Mon Sep 17 00:00:00 2001 From: Hidden Z Date: Sat, 9 Oct 2010 19:31:32 +0000 Subject: [PATCH] injector: use more efficient exists() method --- injector | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/injector b/injector index 72713a2..0754f1d 100755 --- a/injector +++ b/injector @@ -19,13 +19,14 @@ for line in f: # check for already existed hosts in database to avoid adding duplicates # 1. do lookup by hostname # 2. do lookup by base64 hash - if not i2phost.objects.filter(name=entry[0]) \ - and not i2phost.objects.filter(b64hash=entry[1]): - print 'Adding %s' % entry[0] - host = i2phost(name=entry[0], b64hash=entry[1], - description='Auto-added from external hosts.txt', - activated=True) - host.save() + qs1 = i2phost.objects.filter(name=entry[0]) + qs2 = i2phost.objects.filter(name=entry[1]) + if not qs1.exists() and not qs2.exists(): + print 'Adding %s' % entry[0] + host = i2phost(name=entry[0], b64hash=entry[1], + description='Auto-added from external hosts.txt', + activated=True) + host.save() else: print 'Host %s already exists' % entry[0] f.close()