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

[dw-free] Investigate LJ::Knob, remove?

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

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

Remove unused LJ::Knob code.

Patch by [staff profile] denise.

Files modified:
  • bin/upgrading/base-data.sql
  • bin/upgrading/update-db-general.pl
  • cgi-bin/LJ/Knob.pm
  • cgi-bin/ljlib.pl
  • t/knob.t
--------------------------------------------------------------------------------
diff -r d0a7db53ccb1 -r a46c62533652 bin/upgrading/base-data.sql
--- a/bin/upgrading/base-data.sql	Fri Aug 21 03:24:20 2009 +0000
+++ b/bin/upgrading/base-data.sql	Fri Aug 21 00:43:19 2009 -0500
@@ -877,7 +877,6 @@ REPLACE INTO schematables (des, public_b
 REPLACE INTO schematables (des, public_browsable, redist_mode, redist_where, tablename) VALUES ('Global. Stores content marked as spam by users when they delete it, for administrator review.\n\r\nA reported comment, user-to-user message, or community entry is copied into this table, by the LJ::mark_comment_as_spam, LJ::mark_as_spam, or LJ::mark_entry_as_spam function, respectively.\r\n\r\nThe admin tool (/admin/spamreports.bml hinging on siteadmin:spamreports priv) allows spam report viewing: top 10 reported IPs, top 10 reported users (and showing if someone has received a spam warning before), last 10 reports, reports in last 1 hour, 6 hours, and 24 hours; the page supports sorting by open/closed.\r\n\r\nThe \'spamreport_notification\' hook exists for optionally notifying people about spamming.  A maintenance task cleans out data older than 90 days. Please see also the [dbtable[tempanonips]] table.', '0', 'off', NULL, 'spamreports');
 REPLACE INTO schematables (des, public_browsable, redist_mode, redist_where, tablename) VALUES ('Global. Stores contextual product prodding items. (\"Hey, you\'ve never used polls, wanna learn how?\")', '0', 'off', NULL, 'cprodlist');
 REPLACE INTO schematables (des, public_browsable, redist_mode, redist_where, tablename) VALUES ('Global. Stores counter information allocated by the LJ::alloc_global_counter function. Please see also [dbtable[usercounter]].', '0', 'off', NULL, 'counter');
-REPLACE INTO schematables (des, public_browsable, redist_mode, redist_where, tablename) VALUES ('Global. Stores data for LJ::Knob, a class to efficiently support web/config-based tunables.', '0', 'off', NULL, 'knob');
 REPLACE INTO schematables (des, public_browsable, redist_mode, redist_where, tablename) VALUES ('Global. Stores data for RFC 2617 challenge-response digest authentication support - used on-site for logins, commenting, etc. Please see also [dbtable[secrets]].', '0', 'off', NULL, 'challenges');
 REPLACE INTO schematables (des, public_browsable, redist_mode, redist_where, tablename) VALUES ('Global. Stores data for SiteMessages widget (used to post announcements to users).', '0', 'off', NULL, 'site_messages');
 REPLACE INTO schematables (des, public_browsable, redist_mode, redist_where, tablename) VALUES ('Global. Stores data for a rotating secret value on the server, for auth support. Please see also [dbtable[challenges]].', '0', 'off', NULL, 'secrets');
diff -r d0a7db53ccb1 -r a46c62533652 bin/upgrading/update-db-general.pl
--- a/bin/upgrading/update-db-general.pl	Fri Aug 21 03:24:20 2009 +0000
+++ b/bin/upgrading/update-db-general.pl	Fri Aug 21 00:43:19 2009 -0500
@@ -1007,6 +1007,7 @@ register_tabledrop("sms_msgerror");
 register_tabledrop("sms_msgerror");
 register_tabledrop("sms_msgprop");
 register_tabledrop("sms_msgproplist");
+register_tabledrop("knob");
 
 register_tablecreate("portal", <<'EOC');
 CREATE TABLE portal (
@@ -2566,13 +2567,6 @@ CREATE TABLE usersearch_packdata (
 )
 EOC
 
-register_tablecreate("knob", <<'EOC');
-CREATE TABLE knob (
-    knobname    VARCHAR(255) NOT NULL PRIMARY KEY,
-    val         TINYINT UNSIGNED
-)
-EOC
-
 register_tablecreate("debug_notifymethod", <<'EOC');
 CREATE TABLE debug_notifymethod (
     userid       int unsigned not null,
diff -r d0a7db53ccb1 -r a46c62533652 cgi-bin/LJ/Knob.pm
--- a/cgi-bin/LJ/Knob.pm	Fri Aug 21 03:24:20 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-package LJ::Knob;
-use strict;
-use String::CRC32 ();
-
-my %singleton;
-
-# fields:
-#   name
-#   value -- if defined, loaded.  value in range [0,100] (inclusive)
-
-sub instance {
-    my ($class, $knobname) = @_;
-    return $singleton{$knobname} ||= LJ::Knob->new($knobname);
-}
-
-sub new {
-    my ($class, $knobname) = @_;
-    my $self = {
-        name => $knobname,
-    };
-    return bless $self, $class;
-}
-
-sub memkey {
-    my $self = shift;
-    return "knob:$self->{name}";
-}
-
-sub set_value {
-    my ($self, $val) = @_;
-    $val += 0;
-
-    my $memkey = $self->memkey;
-    LJ::MemCache::set($memkey, $val);
-    my $dbh = LJ::get_db_writer();
-    $dbh->do("REPLACE INTO knob (knobname, val) VALUES (?, ?)", undef,
-             $self->{name}, $val);
-
-    # broadcast to other apache nodes to change
-    $self->{value} = $val;
-
-    return 1;
-}
-
-sub value {
-    my $self = shift;
-    return $self->{value} if defined $self->{value};
-    my $name = $self->{name};
-
-    my $memkey = $self->memkey;
-    my $rv = LJ::MemCache::get($memkey);
-    if (defined $rv) {
-        return $self->{value} = $rv;
-    }
-
-    my $dbh = LJ::get_db_writer();
-    $rv = $dbh->selectrow_array("SELECT val FROM knob WHERE knobname=?", undef, $name) + 0;
-    LJ::MemCache::add($memkey, $rv);
-    return $self->{value} = $rv;
-}
-
-sub check {
-    my ($self, $checkon) = @_;
-    my $rand = (127 & int(String::CRC32::crc32($checkon))); # [0 .. 127]
-    my $val  = int(127 * $self->value / 100);               # [0 .. 127]
-    return $rand <= $val;
-}
-
-1;
diff -r d0a7db53ccb1 -r a46c62533652 cgi-bin/ljlib.pl
--- a/cgi-bin/ljlib.pl	Fri Aug 21 03:24:20 2009 +0000
+++ b/cgi-bin/ljlib.pl	Fri Aug 21 00:43:19 2009 -0500
@@ -38,7 +38,6 @@ use Class::Autouse qw(
                       TheSchwartz::Job
                       LJ::Comment
                       LJ::Config
-                      LJ::Knob
                       LJ::ExternalSite
                       LJ::ExternalSite::Vox
                       LJ::Message
diff -r d0a7db53ccb1 -r a46c62533652 t/knob.t
--- a/t/knob.t	Fri Aug 21 03:24:20 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-# -*-perl-*-
-
-use strict;
-use Test::More 'no_plan';
-use lib "$ENV{LJHOME}/cgi-bin";
-require 'ljlib.pl';
-
-my $k;
-
-$k = LJ::Knob->instance("test_knob");
-ok($k);
-
-$k->set_value(50);
-is($k->value, 50, "knob value is 50");
-
-my ($match, $nomatch);
-for (1..500) {
-    if ($k->check($_)) {
-        $match++;
-        die "inconsistent" unless $k->check($_);
-    } else {
-        $nomatch++;
-        die "inconsistent" if $k->check($_);
-    }
-}
-is($match, 269, "269 matched");
-is($nomatch, 231, "231 didn't match");
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org