kareila: (Default)
kareila ([personal profile] kareila) wrote in [site community profile] changelog2009-08-07 05:46 am

[dw-free] investigate LJ::EventLogSink, remove?

[commit: http://hg.dwscoalition.org/dw-free/rev/160d82e2137d]

http://bugs.dwscoalition.org/show_bug.cgi?id=164

Remove unused code.

Patch by [staff profile] denise.

Files modified:
  • cgi-bin/LJ/Config.pm
  • cgi-bin/LJ/EventLogRecord.pm
  • cgi-bin/LJ/EventLogSink.pm
  • cgi-bin/LJ/EventLogSink/Database.pm
  • cgi-bin/ljlib.pl
--------------------------------------------------------------------------------
diff -r 1a8a94ef7fb0 -r 160d82e2137d cgi-bin/LJ/Config.pm
--- a/cgi-bin/LJ/Config.pm	Thu Aug 06 23:57:07 2009 -0500
+++ b/cgi-bin/LJ/Config.pm	Fri Aug 07 00:45:49 2009 -0500
@@ -38,7 +38,6 @@ sub reload {
         $LJ::DBIRole->set_sources(\%LJ::DBINFO);
         LJ::MemCache::reload_conf();
         LJ::ExternalSite->forget_site_objs;
-        LJ::EventLogSink->forget_sink_objs;
         LJ::AccessLogSink->forget_sink_objs;
 
         # reload MogileFS config
diff -r 1a8a94ef7fb0 -r 160d82e2137d cgi-bin/LJ/EventLogRecord.pm
--- a/cgi-bin/LJ/EventLogRecord.pm	Thu Aug 06 23:57:07 2009 -0500
+++ b/cgi-bin/LJ/EventLogRecord.pm	Fri Aug 07 00:45:49 2009 -0500
@@ -3,7 +3,6 @@ package LJ::EventLogRecord;
 
 use strict;
 use Carp qw(croak);
-use Class::Autouse qw(LJ::EventLogSink);
 use TheSchwartz;
 
 use LJ::ModuleLoader;
@@ -90,10 +89,6 @@ sub work {
 
     my $evt = LJ::EventLogRecord::new($evt_class, %params);
 
-    foreach my $sink (LJ::EventLogSink->sinks) {
-        $sink->log($evt) if $sink->should_log($evt);
-    }
-
     $job->completed;
 }
 
diff -r 1a8a94ef7fb0 -r 160d82e2137d cgi-bin/LJ/EventLogSink.pm
--- a/cgi-bin/LJ/EventLogSink.pm	Thu Aug 06 23:57:07 2009 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-package LJ::EventLogSink;
-use strict;
-use LJ::ModuleCheck;
-
-sub new {
-    my $class = shift;
-    die "Cannot call new on EventLogSink base class";
-}
-
-sub log {
-    my ($self, $evt) = @_;
-    die "Cannot call log on EventLogSink base class";
-}
-
-sub should_log {
-    my ($self, $evt) = @_;
-    die "Cannot call should_log on EventLogSink base class";
-}
-
-
-my $need_rebuild = 1;
-my @sinks = ();
-# class method.  called after ljconfig.pl is reloaded
-# to know we need to reconstruct our list of external site
-# instances
-sub forget_sink_objs {
-    $need_rebuild = 1;
-    @sinks = ();
-}
-
-# class method.
-sub sinks {
-    _build_sink_objs() if $need_rebuild;
-    return @sinks;
-}
-
-sub _build_sink_objs {
-    return unless $need_rebuild;
-    $need_rebuild = 0;
-    @sinks = ();
-    foreach my $ci (@LJ::EVENT_LOG_SINKS) {
-        my @args = @$ci;
-        my $class = shift @args;
-        $class = "LJ::EventLogSink::$class" unless $class =~ /::/;
-        unless (LJ::ModuleCheck->have($class)) {
-            warn "Can't load module: $class\n";
-            next;
-        }
-        push @sinks, $class->new(@args);
-    }
-}
-
-
-1;
diff -r 1a8a94ef7fb0 -r 160d82e2137d cgi-bin/LJ/EventLogSink/Database.pm
--- a/cgi-bin/LJ/EventLogSink/Database.pm	Thu Aug 06 23:57:07 2009 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-package LJ::EventLogSink::Database;
-use strict;
-use base 'LJ::EventLogSink';
-
-sub new {
-    my ($class, %opts) = @_;
-
-    my $prefix = $opts{prefix};
-
-    my $self = {
-        prefix => $prefix,
-    };
-
-    bless $self, $class;
-    return $self;
-}
-
-sub database_role {
-    return "logs";
-}
-
-sub prefix {
-    my $self = shift;
-    return $self->{prefix} || 'eventlog';
-}
-
-sub log {
-    my ($self, $evt) = @_;
-
-    return 0 unless $self->should_log($evt);
-
-    my $params = $evt->params
-        or return 0;
-
-    my $event_type = $params->{_event_type} || 'unknown';
-
-    my $dbl = LJ::get_dbh($self->database_role)
-        or return 0;
-
-    my @now = gmtime();
-
-    my $table = $self->prefix .
-        sprintf("%04d%02d%02d%02d",
-                $now[5]+1900,
-                $now[4]+1,
-                $now[3],
-                $now[2]);
-
-    unless ($LJ::CACHED_LOG_CREATE{"$table"}++) {
-        my $sql = "(".
-                "event VARCHAR(255) NOT NULL, " .
-                "unixtimestamp INT UNSIGNED NOT NULL, " .
-                "info BLOB" .
-                ")";
-
-        $dbl->do("CREATE TABLE IF NOT EXISTS $table $sql");
-        die $dbl->errstr if $dbl->err && $LJ::IS_DEV_SERVER;
-        Apache->log_error("error creating log table ($table): Error is: " .
-                          $dbl->err . ": ". $dbl->errstr) if $dbl->err;
-    }
-
-    my $encoded_params = join '&', map { LJ::eurl($_) . '=' . LJ::eurl($params->{$_}) } keys %$params;
-    $dbl->do("INSERT INTO $table (event, unixtimestamp, info) VALUES (?, UNIX_TIMESTAMP(), ?)", undef,
-             $event_type, $encoded_params);
-
-    die $dbl->errstr if $dbl->err;
-
-    return 1;
-}
-
-
-sub should_log {
-    my ($self, $evt) = @_;
-    return 1;
-}
-
-1;
diff -r 1a8a94ef7fb0 -r 160d82e2137d cgi-bin/ljlib.pl
--- a/cgi-bin/ljlib.pl	Thu Aug 06 23:57:07 2009 -0500
+++ b/cgi-bin/ljlib.pl	Fri Aug 07 00:45:49 2009 -0500
@@ -42,7 +42,6 @@ use Class::Autouse qw(
                       LJ::ExternalSite
                       LJ::ExternalSite::Vox
                       LJ::Message
-                      LJ::EventLogSink
                       LJ::PageStats
                       LJ::AccessLogSink
                       LJ::ConvUTF8
--------------------------------------------------------------------------------