Skip to content
This repository
Browse code

More user table fixes. Also fix GH-12.

(Kinda.)
  • Loading branch information...
commit 1dbdca1a650ae0e64fed59d58ef3b2d911b8b3dc 1 parent 0ceb1a5
Eksopl authored March 10, 2012
1  board-reports-demon.pl
@@ -146,6 +146,7 @@ sub do_report{
146 146
 		my $xstart = $list->[0][0];
147 147
 		my $xend   = $list->[-1][0];
148 148
 		open HANDLE,">$loc/graphs/$name.data" or die "$! - $loc/graphs/$name.data";
  149
+		print HANDLE "0\t0\t0\t0\n" if !defined $list->[0][0];
149 150
 		print HANDLE (join "\t",@$_),"\n" foreach @$list;
150 151
 		close HANDLE;
151 152
 		
85  sql/r0142_2.pl
@@ -112,55 +112,68 @@ BEGIN
112 112
 
113 113
 DROP PROCEDURE IF EXISTS `insert_post_$_`//
114 114
 
115  
-CREATE PROCEDURE `insert_post_$_` (o_timestamp INT, media_hash VARCHAR(25), email VARCHAR(100), o_name VARCHAR(100), o_trip VARCHAR(25))
  115
+CREATE PROCEDURE `insert_post_$_` (p_timestamp INT, p_media_hash VARCHAR(25), p_email VARCHAR(100), p_name VARCHAR(100), p_trip VARCHAR(25))
116 116
 BEGIN
117  
-  DECLARE n_day INT;
118  
-  DECLARE n_image INT;
119  
-  DECLARE n_sage INT;
120  
-  DECLARE n_anon INT;
121  
-  DECLARE n_trip INT;
122  
-  DECLARE n_name INT;
  117
+  DECLARE d_day INT;
  118
+  DECLARE d_image INT;
  119
+  DECLARE d_sage INT;
  120
+  DECLARE d_anon INT;
  121
+  DECLARE d_trip INT;
  122
+  DECLARE d_name INT;
123 123
   
124  
-  SET n_day = FLOOR(o_timestamp/86400)*86400;
125  
-  SET n_image = media_hash IS NOT NULL;
126  
-  SET n_sage = COALESCE(email = 'sage', 0);
127  
-  SET n_anon = COALESCE(o_name = 'Anonymous' AND o_trip IS NULL, 0);
128  
-  SET n_trip = o_trip IS NOT NULL;
129  
-  SET n_name = COALESCE(o_name <> 'Anonymous' AND o_trip IS NULL, 1);
  124
+  SET d_day = FLOOR(p_timestamp/86400)*86400;
  125
+  SET d_image = p_media_hash IS NOT NULL;
  126
+  SET d_sage = COALESCE(p_email = 'sage', 0);
  127
+  SET d_anon = COALESCE(p_name = 'Anonymous' AND p_trip IS NULL, 0);
  128
+  SET d_trip = p_trip IS NOT NULL;
  129
+  SET d_name = COALESCE(p_name <> 'Anonymous' AND p_trip IS NULL, 1);
130 130
   
131  
-  INSERT INTO $_\_daily VALUES(n_day, 1, n_image, n_sage, n_anon, n_trip, n_name)
132  
-    ON DUPLICATE KEY UPDATE posts=posts+1, images=images+n_image,
133  
-    sage=sage+n_sage, anons=anons+n_anon, trips=trips+n_trip,
134  
-    names=names+n_name;
135  
-  INSERT INTO $_\_users VALUES(COALESCE(o_name,''), COALESCE(o_trip,''), o_timestamp, 1)
  131
+  INSERT INTO $_\_daily VALUES(d_day, 1, d_image, d_sage, d_anon, d_trip, d_name)
  132
+    ON DUPLICATE KEY UPDATE posts=posts+1, images=images+d_image,
  133
+    sage=sage+d_sage, anons=anons+d_anon, trips=trips+d_trip,
  134
+    names=names+d_name;
  135
+    
  136
+  -- Also should be a transaction. Lol MySQL.  
  137
+  IF (SELECT trip FROM $_\_users WHERE trip = p_trip) IS NOT NULL THEN
  138
+    UPDATE $_\_users SET postcount=postcount+1, 
  139
+      firstseen = LEAST(VALUES(firstseen), firstseen)
  140
+      WHERE trip = p_trip;
  141
+  ELSE
  142
+    INSERT INTO $_\_users VALUES(COALESCE(p_name,''), COALESCE(p_trip,''), p_timestamp, 1)
136 143
     ON DUPLICATE KEY UPDATE postcount=postcount+1,
137 144
     firstseen = LEAST(VALUES(firstseen), firstseen);
  145
+  END IF;
138 146
 END//
139 147
 
140 148
 DROP PROCEDURE IF EXISTS `delete_post_$_`//
141 149
 
142  
-CREATE PROCEDURE `delete_post_$_` (timestamp INT, media_hash VARCHAR(25), email VARCHAR(100), p_name VARCHAR(100), trip VARCHAR(25))
  150
+CREATE PROCEDURE `delete_post_$_` (p_timestamp INT, p_media_hash VARCHAR(25), p_email VARCHAR(100), p_name VARCHAR(100), p_trip VARCHAR(25))
143 151
 BEGIN
144  
-  DECLARE n_day INT;
145  
-  DECLARE n_image INT;
146  
-  DECLARE n_sage INT;
147  
-  DECLARE n_anon INT;
148  
-  DECLARE n_trip INT;
149  
-  DECLARE n_name INT;
  152
+  DECLARE d_day INT;
  153
+  DECLARE d_image INT;
  154
+  DECLARE d_sage INT;
  155
+  DECLARE d_anon INT;
  156
+  DECLARE d_trip INT;
  157
+  DECLARE d_name INT;
150 158
   
151  
-  SET n_day = FLOOR(timestamp/86400)*86400;
152  
-  SET n_image = media_hash IS NOT NULL;
153  
-  SET n_sage = COALESCE(email = 'sage', 0);
154  
-  SET n_anon = COALESCE(p_name = 'Anonymous' AND trip IS NULL, 0);
155  
-  SET n_trip = trip IS NOT NULL;
156  
-  SET n_name = COALESCE(p_name <> 'Anonymous' AND trip IS NULL, 1);
  159
+  SET d_day = FLOOR(p_timestamp/86400)*86400;
  160
+  SET d_image = p_media_hash IS NOT NULL;
  161
+  SET d_sage = COALESCE(p_email = 'sage', 0);
  162
+  SET d_anon = COALESCE(p_name = 'Anonymous' AND p_trip IS NULL, 0);
  163
+  SET d_trip = p_trip IS NOT NULL;
  164
+  SET d_name = COALESCE(p_name <> 'Anonymous' AND p_trip IS NULL, 1);
157 165
   
158  
-  UPDATE $_\_daily SET posts=posts-1, images=images-n_image,
159  
-    sage=sage-n_sage, anons=anons-n_anon, trips=trips-n_trip,
160  
-    names=names-n_name WHERE day = n_day;
  166
+  UPDATE $_\_daily SET posts=posts-1, images=images-d_image,
  167
+    sage=sage-d_sage, anons=anons-d_anon, trips=trips-d_trip,
  168
+    names=names-d_name WHERE day = d_day;
161 169
   
162  
-  UPDATE $_\_users SET postcount = postcount-1 WHERE
163  
-    name = COALESCE(p_name, '') AND trip = COALESCE(p_trip, '');  
  170
+  -- Also should be a transaction. Lol MySQL.
  171
+  IF (SELECT trip FROM $_\_users WHERE trip = p_trip) IS NOT NULL THEN
  172
+    UPDATE $_\_users SET postcount = postcount-1 WHERE trip = p_trip;  
  173
+  ELSE
  174
+    UPDATE $_\_users SET postcount = postcount-1 WHERE
  175
+      name = COALESCE(p_name, '') AND trip = COALESCE(p_trip, '');
  176
+  END IF;
164 177
 END//
165 178
 
166 179
 DROP TRIGGER IF EXISTS `after_ins_$_`//

0 notes on commit 1dbdca1

Please sign in to comment.
Something went wrong with that request. Please try again.