Commits

Anonymous committed ebb7a8f

Start to be lazier about getting children of an object to reduce the API calls required

Comments (0)

Files changed (1)

         self.tid = tid
         self.value = value
         self.children = None
+        self._has_children = False
         # Should this be a weak ref for Pythons GC?
         self.parent = parent
 
         _connect(user, passwd)
 
     def _get_children(self):
-        if self.children is None:
+        if not self._has_children:
             self.children = {}
             companies = _get('/companies/')
             for cmpy in companies:
                 self.children[cmpy['id']] = Company(self, cmpy['id'],
                   cmpy['name'])
+            self._has_children = True
 
     companies = property(lambda self: self._get_children_list())
 
 class Company(TracklrBase):
     def __init__(self, parent, cid, name):
         TracklrBase.__init__(self, 'Company', cid, name, parent)
-        self.name = name
+        self._name = name
 
     def _get_children(self):
-        if self.children is None:
+        if not self._has_children:
             self.children = {}
             clients = _get('/%s/clients/' % self.tid)
             for client in clients:
                 self.children[client['id']] = Client(self, client['id'],
                   client['name'], client['active'])
+            self._has_children = True
 
     clients = property(lambda self: self._get_children_list())
 
         self.active = active
 
     def _get_children(self):
-        if self.children is None:
+        if not self._has_children:
             self.children = {}
             projects = _get('/%s/%s/projects/' %
               (self._find_parent('Company').tid, self.tid))
             for project in projects:
                 self.children[project['id']] = Project(self, project['id'],
                   project['name'], project['active'], project['billable'])
+            self._has_children = True
 
     projects = property(lambda self: self._get_children_list())
 
         self.billable = billable
 
     def _get_children(self):
-        if self.children is None:
+        if not self._has_children:
             self.children = {}
             tasks = _get('/%s/%s/%s/tasks/' % (self._find_parent('Company').tid,
                 self._find_parent('Client').tid, self.tid))
             for task in tasks:
                 self.children[task['id']] = Task(self, task['id'], task['name'],
                   task['active'], task['billable'])
+            self._has_children = True
 
     tasks = property(lambda self: self._get_children_list())
 
         self.billable = billable
 
     def _get_children(self):
-        if self.children is None:
+        if not self._has_children:
             self.children = {}
             events = _get('/%s/%s/%s/%s/events/' %
               (self._find_parent('Company').tid,
                 self.children[event['id']] = Event(self, event['id'],
                   event['log'], event['start'], event['stop'],
                   event['billable'], event['in_progress'])
+            self._has_children = True
 
     events = property(lambda self: self._get_children_list())