Skip to content

Commit

Permalink
Merge pull request #5 from andrewmcgilvray/master
Browse files Browse the repository at this point in the history
Reduce mongodb queries to 2
  • Loading branch information
naparuba committed May 13, 2014
2 parents 1c47941 + 5ae7136 commit de58f93
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,23 @@ def hook_load_retention(self, daemon):
ret_hosts = {}
ret_services = {}

# We must load the data and format as the scheduler want :)
found_hosts = {}
found_services = {}

for h in self.hosts_fs.find():
val = h.get('value', None)
if val is not None:
found_hosts[h.get('_id')] = val

for s in self.services_fs.find():
val = s.get('value', None)
if val is not None:
found_services[s.get('_id')] = val

for h in daemon.hosts:
key = "HOST-%s" % h.host_name
e = self.hosts_fs.find_one({'_id':key})
val = None
if e:
val = e.get('value', None)
if val is not None:
if key in found_hosts:
val = found_hosts[key]
val = base64.b64decode(val)
val = cPickle.loads(val)
ret_hosts[h.host_name] = val
Expand All @@ -231,16 +240,12 @@ def hook_load_retention(self, daemon):
key = "SERVICE-%s,%s" % (s.host.host_name, s.service_description)
# space are not allowed in memcache key.. so change it by SPACE token
key = key.replace(' ', 'SPACE')

val = None
e = self.services_fs.find_one({'_id':key})
if e:
val = e.get('value', None)
if val is not None:
if key in found_services:
val = found_services[key]
val = base64.b64decode(val)
val = cPickle.loads(val)
ret_services[(s.host.host_name, s.service_description)] = val

all_data = {'hosts': ret_hosts, 'services': ret_services}

# Ok, now comme load them scheduler :)
Expand Down

0 comments on commit de58f93

Please sign in to comment.