Mapper: use md5 hashes for database indexes
indexing the full path exeeds the maximum index length for MySQL
This commit is contained in:
parent
b44c18d164
commit
0c05244f8b
|
@ -108,6 +108,14 @@
|
||||||
<length>512</length>
|
<length>512</length>
|
||||||
</field>
|
</field>
|
||||||
|
|
||||||
|
<field>
|
||||||
|
<name>logic_path_hash</name>
|
||||||
|
<type>text</type>
|
||||||
|
<default></default>
|
||||||
|
<notnull>true</notnull>
|
||||||
|
<length>32</length>
|
||||||
|
</field>
|
||||||
|
|
||||||
<field>
|
<field>
|
||||||
<name>physic_path</name>
|
<name>physic_path</name>
|
||||||
<type>text</type>
|
<type>text</type>
|
||||||
|
@ -116,11 +124,19 @@
|
||||||
<length>512</length>
|
<length>512</length>
|
||||||
</field>
|
</field>
|
||||||
|
|
||||||
|
<field>
|
||||||
|
<name>physic_path_hash</name>
|
||||||
|
<type>text</type>
|
||||||
|
<default></default>
|
||||||
|
<notnull>true</notnull>
|
||||||
|
<length>32</length>
|
||||||
|
</field>
|
||||||
|
|
||||||
<index>
|
<index>
|
||||||
<name>file_map_lp_index</name>
|
<name>file_map_lp_index</name>
|
||||||
<unique>true</unique>
|
<unique>true</unique>
|
||||||
<field>
|
<field>
|
||||||
<name>logic_path</name>
|
<name>logic_path_hash</name>
|
||||||
<sorting>ascending</sorting>
|
<sorting>ascending</sorting>
|
||||||
</field>
|
</field>
|
||||||
</index>
|
</index>
|
||||||
|
@ -129,7 +145,7 @@
|
||||||
<name>file_map_pp_index</name>
|
<name>file_map_pp_index</name>
|
||||||
<unique>true</unique>
|
<unique>true</unique>
|
||||||
<field>
|
<field>
|
||||||
<name>physic_path</name>
|
<name>physic_path_hash</name>
|
||||||
<sorting>ascending</sorting>
|
<sorting>ascending</sorting>
|
||||||
</field>
|
</field>
|
||||||
</index>
|
</index>
|
||||||
|
|
|
@ -114,8 +114,8 @@ class Mapper
|
||||||
|
|
||||||
private function resolveLogicPath($logicPath) {
|
private function resolveLogicPath($logicPath) {
|
||||||
$logicPath = $this->stripLast($logicPath);
|
$logicPath = $this->stripLast($logicPath);
|
||||||
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `logic_path` = ?');
|
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `logic_path_hash` = ?');
|
||||||
$result = $query->execute(array($logicPath));
|
$result = $query->execute(array(md5($logicPath)));
|
||||||
$result = $result->fetchRow();
|
$result = $result->fetchRow();
|
||||||
|
|
||||||
return $result['physic_path'];
|
return $result['physic_path'];
|
||||||
|
@ -123,8 +123,8 @@ class Mapper
|
||||||
|
|
||||||
private function resolvePhysicalPath($physicalPath) {
|
private function resolvePhysicalPath($physicalPath) {
|
||||||
$physicalPath = $this->stripLast($physicalPath);
|
$physicalPath = $this->stripLast($physicalPath);
|
||||||
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `physic_path` = ?');
|
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `physic_path_hash` = ?');
|
||||||
$result = $query->execute(array($physicalPath));
|
$result = $query->execute(array(md5($physicalPath)));
|
||||||
$result = $result->fetchRow();
|
$result = $result->fetchRow();
|
||||||
|
|
||||||
return $result['logic_path'];
|
return $result['logic_path'];
|
||||||
|
@ -151,8 +151,8 @@ class Mapper
|
||||||
}
|
}
|
||||||
|
|
||||||
private function insert($logicPath, $physicalPath) {
|
private function insert($logicPath, $physicalPath) {
|
||||||
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*file_map`(`logic_path`,`physic_path`) VALUES(?,?)');
|
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*file_map`(`logic_path`, `physic_path`, `logic_path_hash`, `physic_path_hash`) VALUES(?, ?, ?, ?)');
|
||||||
$query->execute(array($logicPath, $physicalPath));
|
$query->execute(array($logicPath, $physicalPath, md5($logicPath), md5($physicalPath)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function slugifyPath($path, $index=null) {
|
private function slugifyPath($path, $index=null) {
|
||||||
|
|
Loading…
Reference in New Issue