about summary refs log tree commit homepage
path: root/lib/PublicInbox/V2Writable.pm
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-29 09:57:50 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-29 10:00:02 +0000
commit623136f21efe82bf88fcd7fc4c733502c59f63e8 (patch)
treeb8f7ef13ff242fbde2ee84a03e284bbca93f475a /lib/PublicInbox/V2Writable.pm
parentcc44146289bd38a5f95d5dbab8b28016f2599fcb (diff)
downloadpublic-inbox-623136f21efe82bf88fcd7fc4c733502c59f63e8.tar.gz
Purging existing messages is fairly straightforward since we can
take advantage of Xapian and lookup the git object_id with it.

Unfortunately, purging an already "removed" message (which is
no longer in Xapian) is not as easy and we'll need to expose
->purge_oids to purge by the git object_id (currently SHA-1).

Furthermore, we expire reflogs and prune in hopes a dumb HTTP
client won't get the object.
Diffstat (limited to 'lib/PublicInbox/V2Writable.pm')
-rw-r--r--lib/PublicInbox/V2Writable.pm39
1 files changed, 34 insertions, 5 deletions
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 9b280c68..ef9867de 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -209,11 +209,22 @@ sub idx_init {
         $skel->_msgmap_init->{dbh}->begin_work;
 }
 
-sub remove {
-        my ($self, $mime, $cmt_msg) = @_;
+sub purge_oids {
+        my ($self, $purge) = @_; # $purge = { $object_id => 1, ... }
+        $self->done;
+        my $pfx = "$self->{-inbox}->{mainrepo}/git";
+        foreach my $i (0..$self->{max_git}) {
+                my $git = PublicInbox::Git->new("$pfx/$i.git");
+                my $im = $self->import_init($git, 0);
+                $im->purge_oids($purge);
+        }
+}
+
+sub remove_internal {
+        my ($self, $mime, $cmt_msg, $purge) = @_;
         $self->barrier;
         $self->idx_init;
-        my $im = $self->importer;
+        my $im = $self->importer unless $purge;
         my $ibx = $self->{-inbox};
         my $srch = $ibx->search;
         my $cid = content_id($mime);
@@ -245,11 +256,15 @@ sub remove {
                                 # no bugs in our deduplication code:
                                 $removed = $smsg;
                                 $removed->{mime} = $cur;
-                                $im->remove(\$orig, $cmt_msg);
+                                my $oid = $smsg->{blob};
+                                if ($purge) {
+                                        $purge->{$oid} = 1;
+                                } else {
+                                        $im->remove(\$orig, $cmt_msg);
+                                }
                                 $orig = undef;
                                 $removed->num; # memoize this for callers
 
-                                my $oid = $smsg->{blob};
                                 foreach my $idx (@$parts, $skel) {
                                         $idx->remote_remove($oid, $mid);
                                 }
@@ -258,9 +273,23 @@ sub remove {
                 });
                 $self->barrier;
         }
+        if ($purge && scalar keys %$purge) {
+                purge_oids($self, $purge);
+        }
         $removed;
 }
 
+sub remove {
+        my ($self, $mime, $cmt_msg) = @_;
+        remove_internal($self, $mime, $cmt_msg);
+}
+
+sub purge {
+        my ($self, $mime) = @_;
+        remove_internal($self, $mime, undef, {});
+}
+
+
 sub done {
         my ($self) = @_;
         my $locked = defined $self->{idx_parts};