def _sendPartialSubscription(self, connectedChannel, schema_name, typename, fieldname_and_value, typedef, identities, identities_left_to_send, BATCH_SIZE=100, checkPending=True): # get some objects to send kvs = {} index_vals = {} to_send = [] if checkPending: for transactionMessage in self._pendingSubscriptionRecheck: for key in transactionMessage.writes: transactionMessage.writes[key] # if we write to a key we've already sent, we'll need to resend it identity = key.objId if identity in identities: identities_left_to_send.add(identity) for add_index_key in transactionMessage.set_adds: add_index_identities = transactionMessage.set_adds[ add_index_key] fieldDef = self._currentTypeMap().fieldIdToDef[ add_index_key.fieldId] if schema_name == fieldDef.schema and typename == fieldDef.typename and ( fieldname_and_value is None and fieldDef.fieldname == " exists" or fieldname_and_value is not None and tuple(fieldname_and_value) == (fieldDef.fieldname, add_index_key.indexValue)): identities_left_to_send.update(add_index_identities) while identities_left_to_send and (BATCH_SIZE is None or len(to_send) < BATCH_SIZE): to_send.append(identities_left_to_send.pop()) for fieldname in typedef.fields: fieldId = self._currentTypeMap().fieldIdFor( schema_name, typename, fieldname) keys = [ ObjectFieldId(fieldId=fieldId, objId=identity) for identity in to_send ] vals = self._kvstore.getSeveral(keys) for i in range(len(keys)): kvs[keys[i]] = vals[i] index_vals = self._buildIndexValueMap(typedef, schema_name, typename, to_send) connectedChannel.channel.write( ServerToClient.SubscriptionData( schema=schema_name, typename=typename, fieldname_and_value=fieldname_and_value, values=kvs, index_values=index_vals, identities=None if fieldname_and_value is None else tuple(to_send)))
def _sendPartialSubscription( self, connectedChannel, schema_name, typename, fieldname_and_value, typedef, identities, identities_left_to_send, BATCH_SIZE=100, checkPending=True ): #get some objects to send kvs = {} index_vals = {} to_send = [] if checkPending: for transactionMessage in self._pendingSubscriptionRecheck: for key in transactionMessage.writes: val = transactionMessage.writes[key] #if we write to a key we've already sent, we'll need to resend it identity = keymapping.split_data_key(key)[2] if identity in identities: identities_left_to_send.add(identity) for add_index_key in transactionMessage.set_adds: add_index_identities = transactionMessage.set_adds[add_index_key] add_schema, add_typename, add_fieldname, add_hashVal = keymapping.split_index_key_full(add_index_key) if add_schema == schema_name and add_typename == typename and ( fieldname_and_value is None and add_fieldname == " exists" or fieldname_and_value is not None and tuple(fieldname_and_value) == (add_fieldname, add_hashVal) ): identities_left_to_send.update(add_index_identities) while identities_left_to_send and (BATCH_SIZE is None or len(to_send) < BATCH_SIZE): to_send.append(identities_left_to_send.pop()) for fieldname in typedef.fields: keys = [keymapping.data_key_from_names(schema_name, typename, identity, fieldname) for identity in to_send] vals = self._kvstore.getSeveral(keys) for i in range(len(keys)): kvs[keys[i]] = vals[i] index_vals = self._buildIndexValueMap(typedef, schema_name, typename, to_send) connectedChannel.channel.write( ServerToClient.SubscriptionData( schema=schema_name, typename=typename, fieldname_and_value=fieldname_and_value, values=kvs, index_values=index_vals, identities=None if fieldname_and_value is None else tuple(to_send) ) )