def populate_change_metadata(change, data_source_type, data_source_name): from corehq.apps.change_feed.exceptions import MissingMetaInformationError from corehq.apps.change_feed.document_types import ( change_meta_from_doc_meta_and_document, change_meta_from_hard_delete, get_doc_meta_object_from_document, ) if change.metadata: return document = change.get_document() if change.deleted: change.metadata = change_meta_from_hard_delete(document, data_source_type, data_source_name) return try: doc_meta = get_doc_meta_object_from_document(document) change_meta = change_meta_from_doc_meta_and_document( doc_meta=doc_meta, document=document, data_source_type=data_source_type, data_source_name=data_source_name, doc_id=change.id, ) except MissingMetaInformationError: pass else: change.metadata = change_meta
def _doc_to_changes(self, doc): # creates a change object for the last form submission # for the user to each of their apps. # this allows us to reindex for the app status report # without reindexing all forms. changes = [] forms = get_last_forms_by_app(doc['_id']) for form in forms: doc_meta = get_doc_meta_object_from_document(form) change_meta = change_meta_from_doc_meta_and_document( doc_meta=doc_meta, document=form, data_source_type='elasticsearch', data_source_name='hqforms', ) changes.append( Change( id=change_meta.document_id, sequence_id=None, document=form, deleted=change_meta.is_deletion, metadata=change_meta, document_store=None, )) return changes
def _doc_to_change(doc, data_source_type, data_source_name): doc_meta = get_doc_meta_object_from_document(doc) change_meta = change_meta_from_doc_meta_and_document( doc_meta=doc_meta, document=doc, data_source_type=data_source_type, data_source_name=data_source_name, ) return Change( id=change_meta.document_id, sequence_id=None, document=doc, deleted=change_meta.is_deletion, metadata=change_meta, document_store=None, )
def _doc_to_change(doc, data_source_type, data_source_name): doc_meta = get_doc_meta_object_from_document(doc) change_meta = change_meta_from_doc_meta_and_document( doc_meta=doc_meta, document=doc, data_source_type=data_source_type, data_source_name=data_source_name, ) return Change( id=change_meta.document_id, sequence_id=None, document=doc, deleted=change_meta.is_deletion, metadata=change_meta, document_store=None, )
def process_change(self, pillow_instance, change): try: document = change.get_document() doc_meta = get_doc_meta_object_from_document(document) change_meta = change_meta_from_doc_meta_and_document( doc_meta=doc_meta, document=document, data_source_type=self._data_source_type, data_source_name=self._data_source_name, doc_id=change.id, ) except MissingMetaInformationError: pass else: # change.deleted is used for hard deletions whereas change_meta.is_deletion is for soft deletions. # from the consumer's perspective both should be counted as deletions so just "or" them # note: it is strange and hard to reproduce that the couch changes feed is providing a "doc" # along with a hard deletion, but it is doing that in the wild so we might as well support it. change_meta.is_deletion = change_meta.is_deletion or change.deleted self._producer.send_change(get_topic(doc_meta), change_meta)
def process_change(self, pillow_instance, change): try: document = change.get_document() doc_meta = get_doc_meta_object_from_document(document) change_meta = change_meta_from_doc_meta_and_document( doc_meta=doc_meta, document=document, data_source_type=self._data_source_type, data_source_name=self._data_source_name, doc_id=change.id, ) except MissingMetaInformationError: pass else: # change.deleted is used for hard deletions whereas change_meta.is_deletion is for soft deletions. # from the consumer's perspective both should be counted as deletions so just "or" them # note: it is strange and hard to reproduce that the couch changes feed is providing a "doc" # along with a hard deletion, but it is doing that in the wild so we might as well support it. change_meta.is_deletion = change_meta.is_deletion or change.deleted self._producer.send_change(get_topic(doc_meta), change_meta)
def populate_change_metadata(change, data_source_type, data_source_name): from corehq.apps.change_feed.exceptions import MissingMetaInformationError from corehq.apps.change_feed.document_types import get_doc_meta_object_from_document from corehq.apps.change_feed.document_types import change_meta_from_doc_meta_and_document if change.metadata: return try: document = change.get_document() doc_meta = get_doc_meta_object_from_document(document) change_meta = change_meta_from_doc_meta_and_document( doc_meta=doc_meta, document=document, data_source_type=data_source_type, data_source_name=data_source_name, doc_id=change.id, ) except MissingMetaInformationError: pass else: change.metadata = change_meta
def _doc_to_changes(self, doc): # creates a change object for the last form submission # for the user to each of their apps. # this allows us to reindex for the app status report # without reindexing all forms. changes = [] forms = get_last_forms_by_app(doc['_id']) for form in forms: doc_meta = get_doc_meta_object_from_document(form) change_meta = change_meta_from_doc_meta_and_document( doc_meta=doc_meta, document=form, data_source_type='elasticsearch', data_source_name='hqforms', ) changes.append(Change( id=change_meta.document_id, sequence_id=None, document=form, deleted=change_meta.is_deletion, metadata=change_meta, document_store=None, )) return changes