feat(smbdb): only update hosts if they have changed to improve SQL write time

main
Marshall Hallenbeck 2023-03-08 13:03:48 -05:00
parent 3143b56060
commit 515209a4e0
1 changed files with 4 additions and 1 deletions

View File

@ -165,6 +165,7 @@ class database:
def add_computer(self, ip, hostname, domain, os, smbv1, signing, spooler=None, zerologon=None, petitpotam=None, dc=None):
"""
Check if this host has already been added to the database, if not, add it in.
TODO: return inserted or updated row ids as a list
"""
domain = domain.split('.')[0].upper()
hosts = []
@ -216,7 +217,9 @@ class database:
computer_data["petitpotam"] = petitpotam
if dc is not None:
computer_data["dc"] = dc
hosts.append(computer_data)
# only add computer to be updated if it has changed
if computer_data not in hosts:
hosts.append(computer_data)
logging.debug(f"Update Hosts: {hosts}")
# TODO: find a way to abstract this away to a single Upsert call