aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2017-08-31 13:30:57 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2017-08-31 13:30:57 +0200
commit6870d32ce51bdcdbe75b939dfe1188d451b12bed (patch)
tree1b0e66099dd54b3332ae24672f182e3eea442b93
parentd507038754eb5b31ede7dcf7d7bf0e7845398406 (diff)
downloadsavane-gray-6870d32ce51bdcdbe75b939dfe1188d451b12bed.tar.gz
savane-gray-6870d32ce51bdcdbe75b939dfe1188d451b12bed.tar.bz2
sv_spamchecker: New subcommand 'usercheck'
-rwxr-xr-xbackend/misc/sv_spamchecker150
1 files changed, 91 insertions, 59 deletions
diff --git a/backend/misc/sv_spamchecker b/backend/misc/sv_spamchecker
index e33b4a3..10242c8 100755
--- a/backend/misc/sv_spamchecker
+++ b/backend/misc/sv_spamchecker
@@ -46,6 +46,17 @@ my $verbose;
my %stats;
my $spamc;
+sub item_tag {
+ my ($tracker, $item_id, $comment_id) = @_;
+ if (defined($item_id)) {
+ $tracker .= '#' . $item_id;
+ if ($comment_id) {
+ $tracker .= 'c' . $comment_id;
+ }
+ }
+ return $tracker;
+}
+
sub parse_time_interval {
my $input = shift;
@@ -144,9 +155,9 @@ sub adjust_spamscore {
sub check_tracker_comment {
my ($tracker, $item_id, $comment_id, %opts) = @_;
- debug("checking entry: "
+ debug("checking "
. (exists($opts{queue_id}) ? "queue_id=$opts{queue_id}, " : '')
- . "tracker=$tracker, item_id=$item_id, comment_id=$comment_id");
+ . item_tag($tracker, $item_id, $comment_id));
if (exists($opts{queue_id})) {
db_delete(table => "trackers_spamcheck_queue",
@@ -188,9 +199,12 @@ sub check_tracker_comment {
'bug_id=? LIMIT 1',
$item_id);
}
-
- my $tag = "$tracker#$item_id";
- $tag .= "c$comment_id" if $comment_id;
+
+ if (exists($opts{spamscore})) {
+ $spamscore = $opts{spamscore};
+ }
+
+ my $tag = item_tag($tracker, $item_id, $comment_id);
if ($spamscore < 5) {
# The item was unflagged
@@ -309,9 +323,9 @@ sub learn_from_item {
$ref->{text});
my $learntype = ($ref->{spamscore} > 4) ? TYPE_SPAM : TYPE_HAM;
+ my $tag = item_tag($tracker, $ref->{item_id}, $ref->{comment_id});
+
if (debug()) {
- my $tag = "$tracker#$ref->{item_id}";
- $tag .= ", comment \#$ref->{comment_id}" if $ref->{comment_id};
logit("debug", "$tag: $ref->{uid} $ref->{spamscore} $isspam{$learntype}");
}
@@ -324,7 +338,8 @@ sub learn_from_item {
return if dry_run();
my $res = $spamc->learn($ref->{text}, $learntype);
- logit('err', "Error learning from $tracker:$ref->{item_id}" . $spamc->{resp_msg}) unless defined $res;
+ logit('err', "Error learning from $tag: " . $spamc->{resp_msg})
+ unless defined $res;
db_modify(qq{
INSERT INTO trackers_spamcheck_cache (artifact, item_id, comment_id, isspam)
VALUES (?, ?, ?, ?)
@@ -435,45 +450,22 @@ WHERE $cond},
return @userlist;
}
-sub com_mark {
+sub userproc {
+ my $cb = shift;
+
my @ulist = userlist_collect(@_);
foreach my $user (@ulist) {
if ($user->{resume} ne '') {
debug("$user->{user_name}: resume");
- unless (dry_run()) {
- db_insert({
- table => 'trackers_spamcheck_queue',
- values => {
- artifact => 'resume',
- item_id => $user->{user_id},
- comment_id => 0,
- priority => 3
- },
- update => {
- priority => 3,
- }
- });
- db_modify(q{UPDATE user SET resume_spamscore=? WHERE user_id=?},
- 8, $user->{user_id});
- }
+ &{$cb}($user, 'resume', $user->{user_id}, 0);
}
foreach my $t (TrackerNames()) {
db_foreach(
sub {
my $ref = shift;
- debug("$user->{user_name}: $t#$ref->{bug_id}");
- db_insert({ table => 'trackers_spamcheck_queue',
- values => {
- artifact => $t,
- item_id => $ref->{bug_id},
- comment_id => 0,
- priority => 3
- },
- update => {
- priority => 3,
- }
- }) unless dry_run();
+ debug("$user->{user_name}: ". item_tag($t, $ref->{bug_id}));
+ &{$cb}($user, $t, $ref->{bug_id}, 0);
},
qq{
SELECT tracker.bug_id AS bug_id
@@ -488,18 +480,9 @@ ORDER BY tracker.date
db_foreach(
sub {
my $ref = shift;
- debug("$user->{user_name}: $t#$ref->{bug_id}c$ref->{comment_id}");
- db_insert({ table => 'trackers_spamcheck_queue',
- values => {
- artifact => $t,
- item_id => $ref->{bug_id},
- comment_id => $ref->{comment_id},
- priority => 3
- },
- update => {
- priority => 3,
- }
- }) unless dry_run();
+ debug("$user->{user_name}: "
+ . item_tag($t, $ref->{bug_id}, $ref->{comment_id}));
+ &{$cb}($user, $t, $ref->{bug_id}, $ref->{comment_id});
},
qq{
SELECT history.bug_history_id AS comment_id,
@@ -512,23 +495,65 @@ LEFT JOIN user_group grp
WHERE history.field_name='details' AND history.mod_by=? AND grp.user_group_id IS NULL
ORDER BY history.date},
$user->{user_id}, $user->{user_id});
-
- unless (dry_run()) {
- db_modify(qq{UPDATE $t SET spamscore=8 WHERE submitted_by=?},
- $user->{user_id});
- db_modify(qq{UPDATE ${t}_history SET spamscore=8 WHERE field_name=? AND mod_by=?},
- 'details', $user->{user_id});
- }
}
}
}
+sub com_mark {
+ userproc(
+ sub {
+ return if dry_run();
+
+ my ($user, $tracker, $bug_id, $comment_id) = @_;
+
+ db_insert({ table => 'trackers_spamcheck_queue',
+ values => {
+ artifact => $tracker,
+ item_id => $bug_id,
+ comment_id => $comment_id,
+ priority => 3
+ },
+ update => {
+ priority => 3,
+ }
+ });
+
+ if ($tracker eq 'resume') {
+ db_modify(q{UPDATE user SET resume_spamscore=? WHERE user_id=?},
+ 8, $user->{user_id});
+ } elsif ($comment_id == 0) {
+ db_modify(qq{UPDATE $tracker SET spamscore=? WHERE bug_id=?},
+ 8, $bug_id);
+ } else {
+ db_modify(qq{UPDATE ${tracker}_history SET spamscore=? WHERE bug_history_id=?},
+ 8, $comment_id);
+ }
+ },
+ @_);
+}
+
+sub com_usercheck {
+ userproc(
+ sub {
+ my ($user, $tracker, $bug_id, $comment_id) = @_;
+ check_tracker_comment($tracker,
+ $bug_id,
+ $comment_id,
+ spamscore => 8,
+ notify => 0);
+ },
+ @_);
+ update_user_spamscores(U_IDS, [@_]);
+}
+
my %command = (
queue => { code => \&com_check },
learn => { code => \&com_learn, prereq => 'queue' },
# Recompute user spamscore
userscore => { code => \&com_userscore, wantargs => 1 },
mark => { code => \&com_mark, wantargs => 1 },
+ usercheck => { code => \&com_usercheck, wantargs => 1 },
+ usrck => { alias => 'usercheck' }
);
@@ -637,6 +662,8 @@ B<sv_spamchecker>
[B<queue>]
[B<learn>]
[B<userscore>]
+[B<usercheck>]
+[B<usrck>]
[B<mark>] [I<USER>...]
B<sv_spamchecker> [B<-h>] [B<--help>]
@@ -669,11 +696,16 @@ By default, both stages are run in the order they are described above.
To instruct B<sv_spamchecker> to run only a particular stage, supply
an additional argument: B<queue> or B<learn>.
-Two special modes are available, which take optional list of user names
+Three special modes are available, which take optional list of user names
in the command line. When given the B<userscore> argument, B<sv_spamchecker>
recomputes total spam scores for the listed users. When given the B<mark>
-argument, it flags the listed users for subsequent spam checking. If no
-user names are given, both commands apply to all Savane users (use with care).
+argument, it flags the listed users for subsequent spam checking. Finally,
+the B<usercheck> (or B<usrck>) argument recomputes the spam score for the
+given users, which is (equivalent to running B<sv_spamchecker mark I<USERS>;
+sv_spamchecker queue>)
+
+If no user names are given, these three commands apply to all Savane users
+(use with care).
=head1 OPTIONS

Return to:

Send suggestions and report system problems to the System administrator.