From 0c05244f8bdc083f54b01cbde05c3df7bd97e618 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 10 Feb 2013 11:49:37 +0100 Subject: [PATCH] Mapper: use md5 hashes for database indexes indexing the full path exeeds the maximum index length for MySQL --- db_structure.xml | 20 ++++++++++++++++++-- lib/files/mapper.php | 12 ++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/db_structure.xml b/db_structure.xml index fc7f1082ffa..f353ae08098 100644 --- a/db_structure.xml +++ b/db_structure.xml @@ -108,6 +108,14 @@ 512 + + logic_path_hash + text + + true + 32 + + physic_path text @@ -116,11 +124,19 @@ 512 + + physic_path_hash + text + + true + 32 + + file_map_lp_index true - logic_path + logic_path_hash ascending @@ -129,7 +145,7 @@ file_map_pp_index true - physic_path + physic_path_hash ascending diff --git a/lib/files/mapper.php b/lib/files/mapper.php index 90e4e1ca669..71b665e49bb 100644 --- a/lib/files/mapper.php +++ b/lib/files/mapper.php @@ -114,8 +114,8 @@ class Mapper private function resolveLogicPath($logicPath) { $logicPath = $this->stripLast($logicPath); - $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `logic_path` = ?'); - $result = $query->execute(array($logicPath)); + $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `logic_path_hash` = ?'); + $result = $query->execute(array(md5($logicPath))); $result = $result->fetchRow(); return $result['physic_path']; @@ -123,8 +123,8 @@ class Mapper private function resolvePhysicalPath($physicalPath) { $physicalPath = $this->stripLast($physicalPath); - $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `physic_path` = ?'); - $result = $query->execute(array($physicalPath)); + $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `physic_path_hash` = ?'); + $result = $query->execute(array(md5($physicalPath))); $result = $result->fetchRow(); return $result['logic_path']; @@ -151,8 +151,8 @@ class Mapper } private function insert($logicPath, $physicalPath) { - $query = \OC_DB::prepare('INSERT INTO `*PREFIX*file_map`(`logic_path`,`physic_path`) VALUES(?,?)'); - $query->execute(array($logicPath, $physicalPath)); + $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, md5($logicPath), md5($physicalPath))); } private function slugifyPath($path, $index=null) {