Skip to content
Snippets Groups Projects
Commit f56abf7e authored by Tim Steiner's avatar Tim Steiner
Browse files

Reduce the number of calls to hash() and give it extra time to run.

parent aa6ed868
No related branches found
No related tags found
No related merge requests found
......@@ -513,13 +513,8 @@ class Requests_RequestModel extends Unl_Model
$sqlParts = array();
foreach ($models as $model) {
$file = $model['model']->_data['files'][$model['fileId']];
$file['hash'] = hash('whirlpool', $file['data']);
if (strlen($file['data']) >= 0) {
self::_saveFileToDisk($file['data']);
$file['data'] = "''";
} else {
$file['data'] = '0x' . bin2hex($file['data']);
}
$file['hash'] = self::_saveFileToDisk($file['data']);
$file['data'] = "''";
$sqlParts[] = $db->quoteInto('(?, ', $file['title'])
. $db->quoteInto('?, ' , $file['mimeType'])
. $file['data'] . ', '
......@@ -570,13 +565,8 @@ class Requests_RequestModel extends Unl_Model
$sqlParts = array();
foreach ($models as $model) {
$file = $model['model']->_data['files'][$model['fileId']];
$file['hash'] = hash('whirlpool', $file['data']);
if (strlen($file['data']) >= 0) {
self::_saveFileToDisk($file['data']);
$file['data'] = "''";
} else {
$file['data'] = '0x' . bin2hex($file['data']);
}
$file['hash'] = self::_saveFileToDisk($file['data']);
$file['data'] = "''";
$sqlParts[] = $db->quoteInto('(?, ', $file['fileId'])
. $db->quoteInto('?, ' , $file['title'])
. $db->quoteInto('?, ' , $file['mimeType'])
......@@ -654,6 +644,7 @@ class Requests_RequestModel extends Unl_Model
static protected function _saveFileToDisk($data)
{
set_time_limit(30); // hash function may take a while... give it time
$hash = hash('whirlpool', $data);
$path = APPLICATION_DIR
. DIRECTORY_SEPARATOR
......@@ -667,6 +658,7 @@ class Requests_RequestModel extends Unl_Model
@mkdir($path, 0755, true);
}
file_put_contents($path . DIRECTORY_SEPARATOR . $hash, $data);
return $hash;
}
static protected function _loadFileFromDisk($hash)
......@@ -855,8 +847,7 @@ class Requests_RequestModel extends Unl_Model
'type' => $type,
'title' => $title,
'mimeType' => $mimeType,
'data' => $data,
'hash' => hash('whirlpool', $data)
'data' => $data
);
$this->_data['files'][$lowestId] = $newFile;
......@@ -870,7 +861,6 @@ class Requests_RequestModel extends Unl_Model
$this->_data['files'][$id]['title'] = $title;
$this->_data['files'][$id]['mimeType'] = $mimeType;
$this->_data['files'][$id]['data'] = $data;
$this->_data['files'][$id]['hash'] = hash('whirlpool', $data);
$found = true;
}
......@@ -891,8 +881,7 @@ class Requests_RequestModel extends Unl_Model
'type' => $type,
'title' => $title,
'mimeType' => $mimeType,
'data' => $data,
'hash' => hash('whirlpool', $data)
'data' => $data
);
$this->_data['files'][$lowestId] = $newFile;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment