]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Fix for ticket #2804: bad non-cache fallback code for dupe checks of prolific posters
authorBrion Vibber <brion@pobox.com>
Thu, 4 Nov 2010 00:25:29 +0000 (17:25 -0700)
committerBrion Vibber <brion@pobox.com>
Thu, 4 Nov 2010 00:25:29 +0000 (17:25 -0700)
The old code attempted to compare the value of the notice.created field against now() directly, which tends to explode in our current systems. now() comes up as the server/connection local timezone generally, while the created field is currently set as hardcoded UTC from the web servers. This would lead to breakage when we got a difference in seconds that's several hours off in either direction (depending on the local timezone). New code calculates a threshold by subtracting the number of seconds from the current UNIX timestamp and passing that in in correct format for a simple comparison. As a bonus, this should also be more efficient, as it should be able to follow the index on profile_id and created.

classes/Notice.php

index 60989f9bac12025688eb0b8922729d69456eefda..792d6e13161699bb5f3ce62a17a453a7eb47b807 100644 (file)
@@ -524,10 +524,8 @@ class Notice extends Memcached_DataObject
         $notice = new Notice();
         $notice->profile_id = $profile_id;
         $notice->content = $content;
-        if (common_config('db','type') == 'pgsql')
-          $notice->whereAdd('extract(epoch from now() - created) < ' . common_config('site', 'dupelimit'));
-        else
-          $notice->whereAdd('now() - created < ' . common_config('site', 'dupelimit'));
+        $threshold = common_sql_date(time() - common_config('site', 'dupelimit'));
+        $notice->whereAdd(sprintf("created > '%s'", $notice->escape($threshold)));
 
         $cnt = $notice->count();
         return ($cnt == 0);