Commit 944da910 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Entities: Add missing indexes

parent 6eadbeff
......@@ -208,11 +208,14 @@ bool File::createTable( DBConnection dbConnection )
" BEGIN"
" UPDATE " + policy::FileTable::Name + " SET is_present = new.is_present WHERE folder_id = new.id_folder;"
" END";
std::string indexReq = "CREATE INDEX IF NOT EXISTS file_media_id_index ON " +
std::string mediaIndexReq = "CREATE INDEX IF NOT EXISTS file_media_id_index ON " +
policy::FileTable::Name + "(media_id)";
std::string folderIndexReq = "CREATE INDEX IF NOT EXISTS file_folder_id_index ON " +
policy::FileTable::Name + "(folder_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, triggerReq ) &&
sqlite::Tools::executeRequest( dbConnection, indexReq );
sqlite::Tools::executeRequest( dbConnection, mediaIndexReq ) &&
sqlite::Tools::executeRequest( dbConnection, folderIndexReq );
}
std::shared_ptr<File> File::create( MediaLibraryPtr ml, int64_t mediaId, Type type, const fs::IFile& fileFs, int64_t folderId, bool isRemovable )
......
......@@ -92,8 +92,14 @@ bool Folder::createTable( DBConnection connection)
" BEGIN"
" UPDATE " + policy::FolderTable::Name + " SET is_present = new.is_present WHERE device_id = new.id_device;"
" END";
std::string deviceIndexReq = "CREATE INDEX IF NOT EXISTS folder_device_id_idx ON " +
policy::FolderTable::Name + " (device_id)";
std::string parentFolderIndexReq = "CREATE INDEX IF NOT EXISTS parent_folder_id_idx ON " +
policy::FolderTable::Name + " (parent_id)";
return sqlite::Tools::executeRequest( connection, req ) &&
sqlite::Tools::executeRequest( connection, triggerReq );
sqlite::Tools::executeRequest( connection, triggerReq ) &&
sqlite::Tools::executeRequest( connection, deviceIndexReq ) &&
sqlite::Tools::executeRequest( connection, parentFolderIndexReq );
}
std::shared_ptr<Folder> Folder::create( MediaLibraryPtr ml, const std::string& mrl,
......
......@@ -65,6 +65,7 @@ bool History::createTable( DBConnection dbConnection )
"(SELECT id_media FROM " + policy::HistoryTable::Name +
" ORDER BY insertion_date DESC LIMIT -1 OFFSET " + std::to_string( MaxEntries ) + ");"
" END";
// Don't index the id_media field, we don't want to select history records using the media_id
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, triggerReq );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment