Index: branches/5.1.x/core/units/reviews/reviews_tag_processor.php =================================================================== diff -u -N -r13086 -r13435 --- branches/5.1.x/core/units/reviews/reviews_tag_processor.php (.../reviews_tag_processor.php) (revision 13086) +++ branches/5.1.x/core/units/reviews/reviews_tag_processor.php (.../reviews_tag_processor.php) (revision 13435) @@ -1,6 +1,6 @@ Application->recallObject('SpamHelper'); /* @var $spam_helper SpamHelper */ - $spam_helper->InitHelper($main_object->GetDBField('ResourceId'), 'Review', 0); + $spam_helper->InitHelper($main_object->GetDBField('ResourceId'), 'Review', 0, $main_object->GetCol('ResourceId')); return $spam_helper->InSpamControl(); } Index: branches/5.1.x/core/units/helpers/rating_helper.php =================================================================== diff -u -N -r13086 -r13435 --- branches/5.1.x/core/units/helpers/rating_helper.php (.../rating_helper.php) (revision 13086) +++ branches/5.1.x/core/units/helpers/rating_helper.php (.../rating_helper.php) (revision 13435) @@ -1,6 +1,6 @@ Application->getUnitOption($object->Prefix, 'ConfigMapping'); $review_settings = $config_mapping['RatingDelayValue'].':'.$config_mapping['RatingDelayInterval']; - $spam_helper->InitHelper($object->GetDBField('ResourceId'), 'Rating', $review_settings); + $spam_helper->InitHelper($object->GetDBField('ResourceId'), 'Rating', $review_settings, $object->GetCol('ResourceId')); $user_voted = $spam_helper->InSpamControl(); @@ -121,7 +121,7 @@ $config_mapping = $this->Application->getUnitOption($object->Prefix, 'ConfigMapping'); $review_settings = $config_mapping['RatingDelayValue'].':'.$config_mapping['RatingDelayInterval']; - $spam_helper->InitHelper($object->GetDBField('ResourceId'), 'Rating', $review_settings); + $spam_helper->InitHelper($object->GetDBField('ResourceId'), 'Rating', $review_settings, $object->GetCol('ResourceId')); if (!$object->isLoaded() || $spam_helper->InSpamControl()) { return '@err:' . $this->_replaceInPhrase('already_voted'); Index: branches/5.1.x/core/units/helpers/spam_helper.php =================================================================== diff -u -N -r13086 -r13435 --- branches/5.1.x/core/units/helpers/spam_helper.php (.../spam_helper.php) (revision 13086) +++ branches/5.1.x/core/units/helpers/spam_helper.php (.../spam_helper.php) (revision 13435) @@ -1,6 +1,6 @@ ResourceId = $resource_id; $this->DataType = $data_type; + $this->ResourceId = $resource_id; + $this->ListResourceIDs = $list_resource_ids ? $list_resource_ids : Array ($resource_id); if (preg_match('/(.*):(.*)/', $expiration, $regs)) { $delay_value = $this->Application->ConfigValue($regs[1]); @@ -87,22 +97,25 @@ } $keys = Array ( - 'ItemResourceId' => $this->ResourceId, 'IPaddress' => $_SERVER['REMOTE_ADDR'], 'PortalUserId' => $user_id, 'DataType' => $this->DataType, ); if ($as_array) { + $keys['ItemResourceId'] = $this->ResourceId; + return $keys; } $ret = ''; foreach ($keys as $field_name => $field_value) { - $ret .= '('.$field_name.' = '.$this->Conn->qstr($field_value).') AND '; + $ret .= '(' . $field_name . ' = ' . $this->Conn->qstr($field_value) . ') AND '; } - return substr($ret, 0, -5); + $ret .= '(ItemResourceId IN (' . implode(',', $this->ListResourceIDs) . '))'; + + return $ret; } /** @@ -115,6 +128,10 @@ $fields_hash['Expire'] = $this->Expiration; $this->Conn->doInsert($fields_hash, $this->TableName); + + if (!array_key_exists($this->DataType, $this->ExpirationCache)) { + $this->ExpirationCache[$this->DataType][$this->ResourceId] = $this->Expiration; + } } /** @@ -124,13 +141,18 @@ */ function InSpamControl() { - $key_clause = $this->GetKeyClause(); + if (!array_key_exists($this->DataType, $this->ExpirationCache)) { + $key_clause = $this->GetKeyClause(); - $sql = 'SELECT Expire - FROM '.$this->TableName.' - WHERE '.$key_clause; - $expires = $this->Conn->GetOne($sql); + $sql = 'SELECT Expire, ItemResourceId + FROM '.$this->TableName.' + WHERE '.$key_clause; + $this->ExpirationCache[$this->DataType] = $this->Conn->GetCol($sql, 'ItemResourceId'); + } + $cache =& $this->ExpirationCache[$this->DataType]; + $expires = array_key_exists($this->ResourceId, $cache) ? $cache[$this->ResourceId] : false; + if ($expires && $expires < adodb_mktime()) { // spam control record is expired $sql = 'DELETE FROM '.$this->TableName.'