def push_records_to_destination()

in kinto-remote-settings/src/kinto_remote_settings/signer/updater.py [0:0]


    def push_records_to_destination(self, request) -> int:
        dest_records, _dest_timestamp = self.get_destination_records()
        source_records, _source_timestamp = self.get_source_records()
        new_records = records_diff(source_records, dest_records)
        changes_count = len(new_records)

        if len(new_records) == 0:
            return 0

        # Update the destination collection.
        for record in new_records:
            storage_kwargs = {
                "parent_id": self.destination_collection_uri,
                "resource_name": "record",
            }
            try:
                before = self.storage.get(object_id=record[FIELD_ID], **storage_kwargs)
            except RecordNotFoundError:
                before = None

            # Timestamp should be bumped in destination.
            record = {**record}
            del record[FIELD_LAST_MODIFIED]

            deleted = record.get("deleted", False)
            if deleted:
                try:
                    pushed = self.storage.delete(
                        object_id=record[FIELD_ID],
                        **storage_kwargs,
                    )
                    action = ACTIONS.DELETE
                except RecordNotFoundError:
                    # If the record doesn't exists in the destination
                    # we are good and can ignore it.
                    continue
            else:
                if before is None:
                    pushed = self.storage.create(obj=record, **storage_kwargs)
                    action = ACTIONS.CREATE
                else:
                    pushed = self.storage.update(
                        object_id=record[FIELD_ID], obj=record, **storage_kwargs
                    )
                    action = ACTIONS.UPDATE

            matchdict = {
                "bucket_id": self.destination["bucket"],
                "collection_id": self.destination["collection"],
                FIELD_ID: record[FIELD_ID],
            }
            bid = matchdict["bucket_id"]
            cid = matchdict["collection_id"]
            rid = matchdict["id"]
            record_uri = f"/buckets/{bid}/collections/{cid}/records/{rid}"

            notify_resource_event(
                request,
                {"method": "DELETE" if deleted else "PUT", "path": record_uri},
                matchdict=matchdict,
                resource_name="record",
                parent_id=self.destination_collection_uri,
                obj=pushed,
                action=action,
                old=before,
            )

        return changes_count