Skip to content

Commit

Permalink
Save affected instances while tracing applications
Browse files Browse the repository at this point in the history
This rapidly speeds up getting parametrized applications helpers
  • Loading branch information
FrostyX committed Dec 23, 2014
1 parent 4305575 commit 370f424
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 1 addition & 5 deletions tracer/resources/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,4 @@ def helpers(self):
def instances(self):
return Processes.all().filtered(lambda process: process.name == self.name)

@property
def affected_instances(self):
# @TODO Fix circular dependency and move it up
from tracer.resources.tracer import Tracer
return Tracer().trace_application(self.name)
affected_instances = None
2 changes: 1 addition & 1 deletion tracer/resources/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __ne__(self, process):
return not self.__eq__(process)

def __hash__(self):
return hash(self.name)
return hash(self.pid)

@property
def files(self):
Expand Down
11 changes: 8 additions & 3 deletions tracer/resources/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def trace_affected(self, user=None):
memory = Memory.dump_memory(user)
packages = self._modified_packages()

affected = set()
affected = {}
found = []
for package in packages:
for file in self._PACKAGE_MANAGER.package_files(package.name):
Expand All @@ -86,8 +86,13 @@ def trace_affected(self, user=None):
if p.create_time <= package.modified:
found.append(p.pid)
p = self._apply_rules(p)
affected.add(Applications.find(p.name))
return ApplicationsCollection(affected)
a = Applications.find(p.name)

if a.name not in affected:
affected[a.name] = a
affected[a.name].affected_instances = AffectedProcessesCollection()
affected[a.name].affected_instances.append(p)
return ApplicationsCollection(affected.values())

def _apply_rules(self, process):
parent = process.parent
Expand Down

0 comments on commit 370f424

Please sign in to comment.