From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7A59E1FA10 for ; Thu, 27 Aug 2020 12:17:07 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/8] overidx: inline create_ghost sub Date: Thu, 27 Aug 2020 12:17:01 +0000 Message-Id: <20200827121706.4545-4-e@yhbt.net> In-Reply-To: <20200827121706.4545-1-e@yhbt.net> References: <20200827121706.4545-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: There's no need for this to be a separate sub since there's only a single caller. This saves a few kilobytes at least in short-lived processes. --- lib/PublicInbox/OverIdx.pm | 23 ++++++++++------------- t/over.t | 4 ++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/PublicInbox/OverIdx.pm b/lib/PublicInbox/OverIdx.pm index 67f8cf65..6f0477f0 100644 --- a/lib/PublicInbox/OverIdx.pm +++ b/lib/PublicInbox/OverIdx.pm @@ -184,23 +184,20 @@ sub resolve_mid_to_tid { if (my $del = delete $self->{-ghosts_to_delete}) { delete_by_num($self, $_) for @$del; } - $tid // create_ghost($self, $mid); -} - -sub create_ghost { - my ($self, $mid) = @_; - my $id = mid2id($self, $mid); - my $num = next_ghost_num($self); - $num < 0 or die "ghost num is non-negative: $num\n"; - my $tid = next_tid($self); - my $dbh = $self->{dbh}; - $dbh->prepare_cached(<<'')->execute($num, $tid); + $tid // do { # create a new ghost + my $id = mid2id($self, $mid); + my $num = next_ghost_num($self); + $num < 0 or die "ghost num is non-negative: $num\n"; + $tid = next_tid($self); + my $dbh = $self->{dbh}; + $dbh->prepare_cached(<<'')->execute($num, $tid); INSERT INTO over (num, tid) VALUES (?,?) - $dbh->prepare_cached(<<'')->execute($id, $num); + $dbh->prepare_cached(<<'')->execute($id, $num); INSERT INTO id2num (id, num) VALUES (?,?) - $tid; + $tid; + }; } sub merge_threads { diff --git a/t/over.t b/t/over.t index 41c13872..4c8f8098 100644 --- a/t/over.t +++ b/t/over.t @@ -33,9 +33,9 @@ $over->dbh; is($over->sid('hello-world'), $x, 'idempotent across reopen'); $over->each_by_mid('never', sub { fail('should not be called') }); -$x = $over->create_ghost('never'); +$x = $over->resolve_mid_to_tid('never'); is(int($x), $x, 'integer tid for ghost'); -$y = $over->create_ghost('NEVAR'); +$y = $over->resolve_mid_to_tid('NEVAR'); is($y, $x + 1, 'integer tid for ghost increases'); my $ddd = compress('');