source: npl/mailserver/dspam/dspam-3.10.2/src/tools.mysql_drv/purge-4.1.sql @ c5c522c

gcc484ntopperl-5.22
Last change on this file since c5c522c was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 3.2 KB
Line 
1-- $Id: purge-4.1.sql,v 1.11 2010/04/21 21:14:18 sbajic Exp $
2
3--
4-- This file contains statements for purging the DSPAM for MySQL 4.1 or greater.
5--
6
7-- ---------------------------------------------------------------------------
8-- Note: Should you have modified your dspam.conf to have other intervals for
9--       the purging or you have modified the TrainingMode to be other then
10--       'TEFT' then please modify this SQL file to be in sync with your
11--       dspam.conf.
12--
13-- Note: It is difficult to purge neutral tokens with SQL clauses the same way
14--       as dspam_clean is doing it. So you should still run dspam_clean with
15--       the "-u" parameter from time to time.
16-- ---------------------------------------------------------------------------
17
18--
19-- Set some defaults
20--
21SET @TrainingMode    = 'TEFT';      -- Default training mode
22SET @PurgeSignatures = 14;          -- Stale signatures
23SET @PurgeUnused     = 90;          -- Unused tokens
24SET @PurgeHapaxes    = 30;          -- Tokens with less than 5 hits (hapaxes)
25SET @PurgeHits1S     = 15;          -- Tokens with only 1 spam hit
26SET @PurgeHits1I     = 15;          -- Tokens with only 1 innocent hit
27SET @today           = to_days(current_date());
28
29--
30-- Delete tokens with less than 5 hits (hapaxes)
31--
32START TRANSACTION;
33DELETE LOW_PRIORITY QUICK
34  FROM dspam_token_data
35  WHERE from_days(@today-@PurgeHapaxes) > last_hit
36    AND (2*innocent_hits)+spam_hits < 5;
37COMMIT;
38
39--
40-- Delete tokens with only 1 spam hit
41--
42START TRANSACTION;
43DELETE LOW_PRIORITY QUICK
44  FROM dspam_token_data
45  WHERE from_days(@today-@PurgeHits1S) > last_hit
46    AND innocent_hits = 0 AND spam_hits = 1;
47COMMIT;
48
49--
50-- Delete tokens with only 1 innocent hit
51--
52START TRANSACTION;
53DELETE LOW_PRIORITY QUICK
54  FROM dspam_token_data
55  WHERE from_days(@today-@PurgeHits1I) > last_hit
56    AND innocent_hits = 1 AND spam_hits = 0;
57COMMIT;
58
59--
60-- Delete unused tokens, except for TOE, TUM and NOTRAIN modes
61--
62START TRANSACTION;
63DELETE LOW_PRIORITY QUICK
64  FROM t USING dspam_token_data t
65    LEFT JOIN dspam_preferences p ON (p.preference = 'trainingMode' AND p.uid = t.uid)
66    LEFT JOIN dspam_preferences d ON (d.preference = 'trainingMode' AND d.uid = 0)
67  WHERE COALESCE(CONVERT(p.value USING latin1) COLLATE latin1_general_ci,CONVERT(d.value USING latin1) COLLATE latin1_general_ci,CONVERT(@TrainingMode USING latin1) COLLATE latin1_general_ci) NOT IN (_latin1 'TOE',_latin1 'TUM',_latin1 'NOTRAIN')
68    AND from_days(@today-@PurgeUnused) > last_hit;
69COMMIT;
70
71--
72-- Delete TUM tokens seen no more than 50 times
73--
74START TRANSACTION;
75DELETE LOW_PRIORITY QUICK
76  FROM t USING dspam_token_data t
77    LEFT JOIN dspam_preferences p ON (p.preference = 'trainingMode' AND p.uid = t.uid)
78    LEFT JOIN dspam_preferences d ON (d.preference = 'trainingMode' AND d.uid = 0)
79  WHERE COALESCE(CONVERT(p.value USING latin1) COLLATE latin1_general_ci,CONVERT(d.value USING latin1) COLLATE latin1_general_ci,CONVERT(@TrainingMode USING latin1) COLLATE latin1_general_ci) = _latin1 'TUM'
80    AND from_days(@today-@PurgeUnused) > last_hit
81    AND innocent_hits + spam_hits < 50;
82COMMIT;
83
84--
85-- Delete stale signatures
86--
87START TRANSACTION;
88DELETE LOW_PRIORITY QUICK
89  FROM dspam_signature_data
90  WHERE from_days(@today-@PurgeSignatures) > created_on;
91COMMIT;
Note: See TracBrowser for help on using the repository browser.