From nobody Thu Oct 24 04:22:27 2024 Delivered-To: importer2@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=patchew-devel-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1649321270; cv=none; d=zohomail.com; s=zohoarc; b=Y/cVSPYhox5l2zSJ0P96vypYQOtldjlaUCrJwfo74uaV0hjHBqVmrcDLd+K2YsGGDjMXEG8Zg/bnBJG7JdaV1gOzm79BbXssQS9AuBfSLwCwObap1VtYEj9fQBLpI6I3rfPV2OF+aBmKk7Uk88OYRt9WrdkPAXxXdjF6eP94LPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1649321270; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QqpcamrVFZbuvRvhuKyg1HODrG9ZsoEtUw8epTbmfsU=; b=G4EH4kaunkeXBcuWQpcELpOLYs4vxevLPar0FSpaOuduIuXjEwt0Nq51DsinR4TuX+KB2O3p2K4T4J/sKheDe/cvOJHzQkFUmoQdd0RSXiR7vFGVSzujLVScBZn8iSHYjoJ5Z8YmcKUQPQuHbK0xGtLbpezYLmR1jLqVXUtCnyQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1649321270518831.8884656518317; Thu, 7 Apr 2022 01:47:50 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-101-oJd51b6AOyGcKIdPhyMcdw-1; Thu, 07 Apr 2022 04:47:46 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3A0BE2999B49; Thu, 7 Apr 2022 08:47:46 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30A5440D1B98; Thu, 7 Apr 2022 08:47:46 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DE713194034B; Thu, 7 Apr 2022 08:47:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 75D311949763 for ; Thu, 7 Apr 2022 08:47:44 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5CAD72024CC2; Thu, 7 Apr 2022 08:47:44 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast10.extmail.prod.ext.rdu2.redhat.com [10.11.55.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 57AFD2024CC6 for ; Thu, 7 Apr 2022 08:47:23 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5363C1C0784E for ; Thu, 7 Apr 2022 08:47:22 +0000 (UTC) Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-383-LvcMSspONe6bNT3Q104PiA-2; Thu, 07 Apr 2022 04:47:10 -0400 Received: by mail-ej1-f54.google.com with SMTP id bq8so9324414ejb.10 for ; Thu, 07 Apr 2022 01:47:10 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r22-20020a17090638d600b006d584aaa9c9sm7453703ejd.133.2022.04.07.01.47.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 01:47:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649321269; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=QqpcamrVFZbuvRvhuKyg1HODrG9ZsoEtUw8epTbmfsU=; b=UWnaek+qOLMnFjMAOJYkoF9YjBgMHkCsyxVbi6tjohM4GKGO7TV2TVyJ7u/VVPQPAk1Mio /EENE3FD9qKdARE0OhXmKmSs6aool3wYvRs1SbQNevs9LlfjjR4ip1SmR+CIBqoQJfHsEI RXapACasXKtN3JAEIN7HC/KtFw8BflI= X-MC-Unique: oJd51b6AOyGcKIdPhyMcdw-1 X-Original-To: patchew-devel@listman.corp.redhat.com X-MC-Unique: LvcMSspONe6bNT3Q104PiA-2 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=mi3LZ+K8whZrpYQLxGH6/vWEwDHgw3PXqFpgEjBfHh4=; b=dzlQ8kyXCZUPNig7qU/PyYyKp329FM9SOCGWFjqdGbklzi+JT0mewNl3rDADHal+yq nrbIoaTYz8UTijUteiGcQOWGa1G/WBnhNjQAw+paJHuNjxzvat8yVnDuUjeVYYE0U/mJ iLXHlP1W4AK223hqWOqF+VbuB9cBmKmP9iO9XdomaJmpKbJagXvKBbw1A/AeR8l1ESa9 ocGKlbXo8OXctIBNMfXqER/vuadyHGp1IkM6pCKSVKDPJF4qXbC/Mv5M3YCSJkJPU15f +pOuZ44MCcJb11yEbDR/HzobxZ+2qfUQXw2lVDDbKW2+v9ql7uRTug9fyK24X/4jmJ5S ONGw== X-Gm-Message-State: AOAM530lhUfHaWhzpKO3ctRPRhkHz2G14Nf2b2TPPRGnTIWHGArFVQAv 6/ZqfriKP8ZO7/0Hs6JIkql1gqhWPsfX7w== X-Google-Smtp-Source: ABdhPJyxXqKfCqR3mdqers0C8vBA+v1GijhK0xZ1Sp1CRB3eWrfrDE8LFicVuFaU5yzUj3JmbIkk2A== X-Received: by 2002:a17:907:3e12:b0:6da:f8d9:efeb with SMTP id hp18-20020a1709073e1200b006daf8d9efebmr12263131ejc.634.1649321229917; Thu, 07 Apr 2022 01:47:09 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Thu, 7 Apr 2022 10:47:01 +0200 Message-Id: <20220407084704.78533-3-pbonzini@redhat.com> In-Reply-To: <20220407084704.78533-1-pbonzini@redhat.com> References: <20220407084704.78533-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Subject: [Patchew-devel] [PATCH 2/5] models: change ad hoc deblobbing script to migration X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchew-devel-bounces@redhat.com Sender: "Patchew-devel" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=patchew-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1649321271950100003 Content-Type: text/plain; charset="utf-8" The deblobbing script was written to be invoked while the server is running. Change it to a migration for the sake of running it in the developer setup. Signed-off-by: Paolo Bonzini --- .../migrations/0062_deblob_messages.py | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) rename scripts/blob_migrate.py =3D> api/migrations/0062_deblob_messages.py= (51%) diff --git a/scripts/blob_migrate.py b/api/migrations/0062_deblob_messages.= py similarity index 51% rename from scripts/blob_migrate.py rename to api/migrations/0062_deblob_messages.py index ee7ff73..22ee12f 100644 --- a/scripts/blob_migrate.py +++ b/api/migrations/0062_deblob_messages.py @@ -1,9 +1,13 @@ #! /usr/bin/env python3 +from __future__ import unicode_literals =20 -from api.models import Message, Project -from django.db import transaction +from django.db import migrations, transaction =20 -def doit(n=3D1000): +from api import blobs + +def deblob_messages(apps, schema_editor): + Project =3D apps.get_model("api", "Project") + Message =3D apps.get_model("api", "Message") done =3D 0 for p in Project.objects.all(): start =3D Message.objects.filter(project=3Dp, mbox_bytes=3DNone).o= rder_by("-date").first() @@ -12,14 +16,25 @@ def doit(n=3D1000): print(done, p, first_date) with transaction.atomic(): previously =3D done - q =3D Message.objects.filter(project=3Dp, date__lte=3Dfirs= t_date, mbox_bytes=3DNone).order_by("-date")[:n] + q =3D Message.objects.filter(project=3Dp, date__lte=3Dfirs= t_date, mbox_bytes=3DNone).order_by("-date")[:1000] for msg in q: try: - msg.save_mbox(msg.mbox) + mbox_decoded =3D blobs.load_blob(msg.message_id) + msg.mbox_bytes =3D mbox_decoded.encode("utf-8") msg.save() + blobs.delete_blob(msg.message_id) done +=3D 1 except Exception as e: print(msg, type(e)) start =3D msg if done =3D=3D previously and start.date =3D=3D first_date: start =3D None + +class Migration(migrations.Migration): + + dependencies =3D [("api", "0061_message_mbox_bytes")] + + operations =3D [ + migrations.RunPython(deblob_messages, reverse_code=3Dmigrations.Ru= nPython.noop) + ] + --=20 2.35.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://listman.redhat.com/mailman/listinfo/patchew-devel