docs: def store_result_in_db(self, result, always_cache=True):
          """Store a result in the database."""
          job = self[result.key]
  
          def extend_dependent_links():
              with self.lock:
                  new_workflow_id = id(get_workflow(result.value))
                  self.links[new_workflow_id].extend(
                      self.links[id(job.workflow)])
                  del self.links[id(job.workflow)]
  
          def store_result(status):
              result_value_msg = self.registry.to_json(result.value)
              with self.lock:
                  self.cur.execute(
                      'update "jobs" set "result" = ?, '
                      '"status" = ? where "id" = ?;',
                      (result_value_msg, status, result.key))
  
          def acquire_links():
              with self.lock:
                  linked_keys = tuple(self.links[id(job.workflow)])
                  del self.links[id(job.workflow)]
  
                  # update links for jobs up in the call-stack (parent workflows)
                  n_questions = ','.join('?' * len(linked_keys))
                  self.cur.execute(
                      'update "jobs" set "link" = ? where "id" in ({});'
                      .format(n_questions),
                      (result.key,) + linked_keys)
  
                  # jobs that were attached to the parent workflow(s) will not
                  # receive the current result automatically, so we need to force
                  # feed them to the scheduler.
                  attached_keys = ()
                  for k in linked_keys:
                      attached_keys += tuple(self.attached[k])
                      del self.attached[k]
  
              return attached_keys
  
          # if the returned job is not set to be stored, but a parent job
          # is, we still need to store the result.
          if 'store' not in job.hints and not always_cache:
              if job.is_root_node and id(job.workflow) in self.links:
                  if is_workflow(result.value):
                      extend_dependent_links()
                      return ()
                  else:
                      store_result(Status.LINKEE)
                      return acquire_links()
              else:
                  return ()
  
          # if the return value is a workflow, store the workflow, and add
          # links to this job, to be updated when the resolved result comes in
          if is_workflow(result.value):
              store_result(Status.WORKFLOW)
              with self.lock:
                  self.links[id(get_workflow(result.value))].append(result.key)
              if job.is_root_node:
                  extend_dependent_links()
              return ()
  
          store_result(Status.STORED)
          with self.lock:
              attached_keys = tuple(self.attached[result.key])
              del self.attached[result.key]
  
          if job.is_root_node:
              attached_keys += acquire_links()
  
          return attached_keys