summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Laszlo <tim.laszlo@gmail.com>2012-06-15 09:41:50 -0500
committerTim Laszlo <tim.laszlo@gmail.com>2012-06-15 09:41:50 -0500
commitedf1383048bfbd117ec27fb25a74c4b02a430ecd (patch)
tree078bf67f60207291a5628a14090236da8ae7e9d5
parentac829ae7da105070007d7f95882ddff1f6b338f0 (diff)
downloadbcfg2-edf1383048bfbd117ec27fb25a74c4b02a430ecd.tar.gz
bcfg2-edf1383048bfbd117ec27fb25a74c4b02a430ecd.tar.bz2
bcfg2-edf1383048bfbd117ec27fb25a74c4b02a430ecd.zip
DBStats: Load entries in bulk
Improve load time by fetching all entries at once instead of individually.
-rwxr-xr-xsrc/lib/Bcfg2/Server/Reports/importscript.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/lib/Bcfg2/Server/Reports/importscript.py b/src/lib/Bcfg2/Server/Reports/importscript.py
index 4e6ca2b96..14f2bb1f9 100755
--- a/src/lib/Bcfg2/Server/Reports/importscript.py
+++ b/src/lib/Bcfg2/Server/Reports/importscript.py
@@ -178,6 +178,9 @@ def load_stat(cobj, statistics, encoding, vlevel, logger, quick, location):
(client_name, traceback.format_exc().splitlines()[-1]))
+ entries_cache = {}
+ [entries_cache.__setitem__((e.kind, e.name), e) \
+ for e in Entries.objects.all()]
counter_fields = {TYPE_BAD: 0,
TYPE_MODIFIED: 0,
TYPE_EXTRA: 0}
@@ -189,8 +192,11 @@ def load_stat(cobj, statistics, encoding, vlevel, logger, quick, location):
counter_fields[type] = counter_fields[type] + 1
rr = _fetch_reason(x, build_reason_kwargs(x, encoding, logger), logger)
- entry, created = Entries.objects.get_or_create(\
- name=x.get('name'), kind=x.tag)
+ try:
+ entry = entries_cache[(x.tag, x.get('name'))]
+ except KeyError:
+ entry, created = Entries.objects.get_or_create(\
+ name=x.get('name'), kind=x.tag)
Entries_interactions(entry=entry, reason=rr,
interaction=current_interaction,
@@ -204,8 +210,11 @@ def load_stat(cobj, statistics, encoding, vlevel, logger, quick, location):
if good_reason == None:
# Do this once. Really need to fix Reasons...
good_reason = _fetch_reason(x, build_reason_kwargs(x, encoding, logger), logger)
- entry, created = Entries.objects.get_or_create(\
- name=x.get('name'), kind=x.tag)
+ try:
+ entry = entries_cache[(x.tag, x.get('name'))]
+ except KeyError:
+ entry, created = Entries.objects.get_or_create(\
+ name=x.get('name'), kind=x.tag)
Entries_interactions(entry=entry, reason=good_reason,
interaction=current_interaction,
type=TYPE_GOOD).save()