Skip to content

Commit

Permalink
Remove recentactions/actionhistory (#2232)
Browse files Browse the repository at this point in the history
This functionality is presently unused by Dreamwidth and has crufted.
Let's machete it.
  • Loading branch information
zorkian committed Oct 29, 2017
1 parent 9c71daf commit b646cdb
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 137 deletions.
75 changes: 0 additions & 75 deletions bin/maint/clean_caches.pl
Expand Up @@ -270,81 +270,6 @@

# next cluster
}

# move clustered recentaction summaries from their respective clusters
# to the global actionhistory table
print "-I- Migrating recentactions.\n";

foreach my $cid (@LJ::CLUSTERS) {
next unless $cid;

my $dbcm = LJ::get_cluster_master($cid);
unless ($dbcm) {
print " cluster down: $cid\n";
next;
}

unless ($dbcm->do("LOCK TABLES recentactions WRITE")) {
print " db error (lock): " . $dbcm->errstr . "\n";
next;
}

my $sth = $dbcm->prepare
("SELECT what, COUNT(*) FROM recentactions GROUP BY 1");
$sth->execute;
if ($dbcm->err) {
print " db error (select): " . $dbcm->errstr . "\n";
next;
}

my %counts = ();
my $total_ct = 0;
while (my ($what, $ct) = $sth->fetchrow_array) {
$counts{$what} += $ct;
$total_ct += $ct;
}

print " cluster $cid: $total_ct rows\n" if $verbose;

# Note: We can experience failures on both sides of this
# transaction. Either our delete can succeed then
# insert fail or vice versa. Luckily this data is
# for statistical purposes so we can just live with
# the possibility of a small skew.

unless ($dbcm->do("DELETE FROM recentactions")) {
print " db error (delete): " . $dbcm->errstr . "\n";
next;
}

# at this point if there is an error we will ignore it and try
# to insert the count data above anyway
$dbcm->do("UNLOCK TABLES")
or print " db error (unlock): " . $dbcm->errstr . "\n";

# nothing to insert, why bother?
next unless %counts;

# insert summary into global actionhistory table
my @bind = ();
my @vals = ();
while (my ($what, $ct) = each %counts) {
push @bind, "(UNIX_TIMESTAMP(),?,?,?)";
push @vals, $cid, $what, $ct;
}
my $bind = join(",", @bind);

$dbh->do("INSERT INTO actionhistory (time, clusterid, what, count) " .
"VALUES $bind", undef, @vals);
if ($dbh->err) {
print " db error (insert): " . $dbh->errstr . "\n";

# something's badly b0rked, don't try any other clusters for now
last;
}

# next cluster
}
};

1;
3 changes: 1 addition & 2 deletions bin/moveucluster.pl
Expand Up @@ -689,7 +689,6 @@ sub moveUser {
"cmdbuffer" => 1, # pre-flushed
"events" => 1, # handled by qbufferd (not yet used)
"tempanonips" => 1, # temporary ip storage for spam reports
"recentactions" => 1, # pre-flushed by clean_caches
"pendcomments" => 1, # don't need to copy these
"active_user" => 1, # don't need to copy these
"random_user_set" => 1, # "
Expand Down Expand Up @@ -1035,7 +1034,7 @@ sub fetchTableInfo
my $memkey = "moveucluster:" . Digest::MD5::md5_hex(join(",",@tables));
my $tinfo = LJ::MemCache::get($memkey) || {};
foreach my $table (@tables) {
next if grep { $_ eq $table } qw(events cmdbuffer recentactions pendcomments active_user random_user_set dbnotes);
next if grep { $_ eq $table } qw(events cmdbuffer pendcomments active_user random_user_set dbnotes);
next if $tinfo->{$table}; # no need to load this one

# find the index we'll use
Expand Down
29 changes: 2 additions & 27 deletions bin/upgrading/update-db-general.pl
Expand Up @@ -908,6 +908,8 @@
register_tabledrop("comm_promo_list");
register_tabledrop("incoming_email_handle");
register_tabledrop("backupdirty");
register_tabledrop("actionhistory");
register_tabledrop("recentactions");


register_tablecreate("infohistory", <<'EOC');
Expand Down Expand Up @@ -1840,25 +1842,6 @@
)
EOC

# action history tables
register_tablecreate("actionhistory", <<'EOC');
CREATE TABLE actionhistory (
time INT UNSIGNED NOT NULL,
clusterid TINYINT UNSIGNED NOT NULL,
what CHAR(2) NOT NULL,
count INT UNSIGNED NOT NULL DEFAULT 0,
INDEX(time)
)
EOC

# TODO: why is this myisam?
register_tablecreate("recentactions", <<'EOC');
CREATE TABLE recentactions (
what CHAR(2) NOT NULL
) ENGINE=MYISAM
EOC

# external identities
#
# idtype ::=
Expand Down Expand Up @@ -3416,14 +3399,6 @@
"ALTER TABLE includetext MODIFY COLUMN inctext MEDIUMTEXT");
}

foreach my $table (qw(recentactions actionhistory)) {

if (column_type($table, "what") =~ /^char/i) {
do_alter($table,
"ALTER TABLE $table MODIFY COLUMN what VARCHAR(20) NOT NULL");
}
}

# table format totally changed, we'll just truncate and modify
# all of the columns since the data is just summary anyway
if (index_name("active_user", "INDEX:time")) {
Expand Down
27 changes: 1 addition & 26 deletions cgi-bin/LJ/DB.pm
Expand Up @@ -51,7 +51,7 @@ $LJ::DBIRole = new DBI::Role {
"trust_groups", "userpicmap2", "userpic2",
"s2stylelayers2", "s2compiled2", "userlog",
"logtags", "logtagsrecent", "logkwsum",
"recentactions", "usertags", "pendcomments",
"usertags", "pendcomments",
"loginlog", "active_user", "bannotes",
"notifyqueue", "dbnotes", "random_user_set",
"poll2", "pollquestion2", "pollitem2",
Expand Down Expand Up @@ -305,31 +305,6 @@ sub random_cluster {
}


sub note_recent_action {
my ( $cid, $action ) = @_;

# make sure they gave us an action (and it's not a long string)
return undef if ! $action || length( $action ) > 20;

# fall back to selecting a random cluster if none specified
$cid = LJ::DB::random_cluster() unless defined $cid;

# accept a user object
$cid = ref $cid ? $cid->{clusterid} + 0 : $cid + 0;

return undef unless $cid;

my $dbcm = LJ::get_cluster_master( $cid )
or return undef;

# append to recentactions table
$dbcm->do( "INSERT INTO recentactions VALUES (?)", undef, $action );
return undef if $dbcm->err;

return 1;
}


package LJ;

use Carp qw(confess); # import confess into package LJ
Expand Down
3 changes: 0 additions & 3 deletions cgi-bin/LJ/Protocol.pm
Expand Up @@ -1666,9 +1666,6 @@ sub postevent
# argh, this is all too ugly. need to unify more postpost stuff into async
$u->invalidate_directory_record;

# note this post in recentactions table
LJ::DB::note_recent_action($uowner, 'post');

# Insert the slug (try to, this will fail if this slug is already used)
my $slug = LJ::canonicalize_slug( $req->{slug} );
if ( defined $slug && length $slug > 0 ) {
Expand Down
4 changes: 0 additions & 4 deletions cgi-bin/LJ/Sendmail.pm
Expand Up @@ -162,10 +162,6 @@ sub send_mail

# at this point $msg is a MIME::Lite

# note that we sent an email
LJ::DB::note_recent_action( undef, $msg->attr('content-type') =~ /plain/i
? 'email_send_text' : 'email_send_html' );

my $enqueue = sub {
my $starttime = [gettimeofday()];
my $sclient = LJ::theschwartz() or die "Misconfiguration in mail. Can't go into TheSchwartz.";
Expand Down

0 comments on commit b646cdb

Please sign in to comment.