Index: units/helpers/rating_helper.php =================================================================== --- units/helpers/rating_helper.php (revision 13152) +++ units/helpers/rating_helper.php (working copy) @@ -61,7 +61,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')); $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: units/helpers/spam_helper.php =================================================================== --- units/helpers/spam_helper.php (revision 13152) +++ units/helpers/spam_helper.php (working copy) @@ -31,6 +31,13 @@ var $ResourceId = 0; /** + * ResourceId from all items in list + * + * @var Array + */ + var $ListResourceIDs = Array (); + + /** * Type of information to put into spam control * * @var string @@ -44,6 +51,8 @@ */ var $Expiration = 0; + var $ExpirationCache = Array (); + function SpamHelper() { parent::kHelper(); @@ -57,10 +66,11 @@ * @param string $data_type * @param int $expiration */ - function InitHelper($resource_id, $data_type, $expiration) + function InitHelper($resource_id, $data_type, $expiration, $list_resource_ids = Array ()) { + $this->DataType = $data_type; $this->ResourceId = $resource_id; - $this->DataType = $data_type; + $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.' Index: units/reviews/reviews_tag_processor.php =================================================================== --- units/reviews/reviews_tag_processor.php (revision 13152) +++ units/reviews/reviews_tag_processor.php (working copy) @@ -76,7 +76,7 @@ $spam_helper =& $this->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(); }