(self, metas)
Delete blob metadata in bulk

        :param metas: A list of `BlobMeta` objects.
Delete blob metadata in bulk
Delete blob metadata in bulk
def bulk_delete(self, metas):
        """Delete blob metadata in bulk

        :param metas: A list of `BlobMeta` objects.
        """
        if any(meta.id is None for meta in metas):
            raise ValueError("cannot delete unsaved BlobMeta")
        delete_blobs_sql = """
        WITH deleted AS (
            DELETE FROM blobs_blobmeta
            WHERE id IN %s
            RETURNING *
        ), ins AS (
            INSERT INTO blobs_deletedblobmeta (
                "id",
                "domain",
                "parent_id",
                "name",
                "key",
                "type_code",
                "created_on",
                "deleted_on"
            ) (
                SELECT
                    "id",
                    "domain",
                    "parent_id",
                    "name",
                    "key",
                    "type_code",
                    "created_on",
                    %s AS "deleted_on"
                FROM deleted
                WHERE expires_on IS NULL
            ) ON CONFLICT (id) DO UPDATE SET
                name = EXCLUDED.name,
                key = EXCLUDED.key,
                type_code = EXCLUDED.type_code,
                created_on = EXCLUDED.created_on,
                deleted_on = CLOCK_TIMESTAMP()
            WHERE blobs_deletedblobmeta.parent_id = EXCLUDED.parent_id and blobs_deletedblobmeta.key = EXCLUDED.key
        ) SELECT COUNT(*) FROM deleted;
        """
        now = _utcnow()
        parents = defaultdict(list)
        for meta in metas:
            parents[meta.parent_id].append(meta.id)
        for dbname, split_parent_ids in split_list_by_db_partition(parents):
            ids = tuple(m for p in split_parent_ids for m in parents[p])
            with BlobMeta.get_cursor_for_partition_db(dbname) as cursor:
                cursor.execute(delete_blobs_sql, [ids, now])
        deleted_bytes = sum(m.stored_content_length for m in metas)
        metrics_counter('commcare.blobs.deleted.count', value=len(metas))
        metrics_counter('commcare.blobs.deleted.bytes', value=deleted_bytes)
def bulk_delete ( self , metas ) : if any ( meta . id is None for meta in metas ) : raise ValueError ( "cannot delete unsaved BlobMeta" ) delete_blobs_sql = """
        WITH deleted AS (
            DELETE FROM blobs_blobmeta
            WHERE id IN %s
            RETURNING *
        ), ins AS (
            INSERT INTO blobs_deletedblobmeta (
                "id",
                "domain",
                "parent_id",
                "name",
                "key",
                "type_code",
                "created_on",
                "deleted_on"
            ) (
                SELECT
                    "id",
                    "domain",
                    "parent_id",
                    "name",
                    "key",
                    "type_code",
                    "created_on",
                    %s AS "deleted_on"
                FROM deleted
                WHERE expires_on IS NULL
            ) ON CONFLICT (id) DO UPDATE SET
                name = EXCLUDED.name,
                key = EXCLUDED.key,
                type_code = EXCLUDED.type_code,
                created_on = EXCLUDED.created_on,
                deleted_on = CLOCK_TIMESTAMP()
            WHERE blobs_deletedblobmeta.parent_id = EXCLUDED.parent_id and blobs_deletedblobmeta.key = EXCLUDED.key
        ) SELECT COUNT(*) FROM deleted;
        """ now = _utcnow ( ) parents = defaultdict ( list ) for meta in metas : parents [ meta . parent_id ] . append ( meta . id ) for dbname , split_parent_ids in split_list_by_db_partition ( parents ) : ids = tuple ( m for p in split_parent_ids for m in parents [ p ] ) with BlobMeta . get_cursor_for_partition_db ( dbname ) as cursor : cursor . execute ( delete_blobs_sql , [ ids , now ] ) deleted_bytes = sum ( m . stored_content_length for m in metas ) metrics_counter ( 'commcare.blobs.deleted.count' , value = len ( metas ) ) metrics_counter ( 'commcare.blobs.deleted.bytes' , value = deleted_bytes )