def _query_children_for_cache_children(self, items): # first get non-draft in a round-trip to_process_non_drafts = super(DraftModuleStore, self)._query_children_for_cache_children(items) to_process_dict = {} for non_draft in to_process_non_drafts: to_process_dict[Location(non_draft["_id"])] = non_draft # now query all draft content in another round-trip query = { '_id': {'$in': [namedtuple_to_son(as_draft(Location(item))) for item in items]} } to_process_drafts = list(self.collection.find(query)) # now we have to go through all drafts and replace the non-draft # with the draft. This is because the semantics of the DraftStore is to # always return the draft - if available for draft in to_process_drafts: draft_loc = Location(draft["_id"]) draft_as_non_draft_loc = draft_loc.replace(revision=None) # does non-draft exist in the collection # if so, replace it if draft_as_non_draft_loc in to_process_dict: to_process_dict[draft_as_non_draft_loc] = draft # convert the dict - which is used for look ups - back into a list queried_children = to_process_dict.values() return queried_children
def _query_children_for_cache_children(self, items): # first get non-draft in a round-trip query = { '_id': { '$in': [namedtuple_to_son(Location(item)) for item in items] } } return list(self.collection.find(query))
def location_to_query(location, wildcard=True): """ Takes a Location and returns a SON object that will query for that location. Fields in location that are None are ignored in the query If `wildcard` is True, then a None in a location is treated as a wildcard query. Otherwise, it is searched for literally """ query = namedtuple_to_son(Location(location), prefix='_id.') if wildcard: for key, value in query.items(): # don't allow wildcards on revision, since public is set as None, so # its ambiguous between None as a real value versus None=wildcard if value is None and key != '_id.revision': del query[key] return query
def _query_children_for_cache_children(self, items): # first get non-draft in a round-trip query = { '_id': {'$in': [namedtuple_to_son(Location(item)) for item in items]} } return list(self.collection.find(query))