Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F804012
D366.id906.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 26, 9:03 AM
Size
5 KB
Mime Type
text/x-diff
Expires
Thu, Feb 27, 9:03 AM (1 h, 25 m)
Engine
blob
Format
Raw Data
Handle
576729
Attached To
D366: INP-1769 - Truncate search result table instead of dropping it
D366.id906.diff
View Options
Index: core/kernel/db/cat_event_handler.php
===================================================================
--- core/kernel/db/cat_event_handler.php
+++ core/kernel/db/cat_event_handler.php
@@ -1352,17 +1352,21 @@
}
// building final search query
+ $search_table_exists = $this->Conn->Query('SHOW TABLES LIKE "'.$search_table.'"');
+
if (!$this->Application->GetVar('do_not_drop_search_table')) {
- $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); // erase old search table if clean k4 event
+ if ( $search_table_exists ) {
+ $this->Conn->Query('TRUNCATE TABLE '.$search_table);
+ }
+
$this->Application->SetVar('do_not_drop_search_table', true);
}
- $search_table_exists = $this->Conn->Query('SHOW TABLES LIKE "'.$search_table.'"');
if ($search_table_exists) {
$select_intro = 'INSERT INTO '.$search_table.' (Relevance, ItemId, ResourceId, ItemType, EdPick) ';
}
else {
- $select_intro = 'CREATE TABLE '.$search_table.' AS ';
+ $select_intro = 'CREATE TABLE '.$search_table.' ENGINE = MEMORY AS ';
}
$edpick_clause = $this->Application->getUnitOption($event->Prefix.'.EditorsPick', 'Fields') ? $items_table.'.EditorsPick' : '0';
@@ -1647,25 +1651,38 @@
// Building final search query.
$search_table = $search_helper->getSearchTable();
- $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table);
+ $search_table_exists = $this->Conn->Query('SHOW TABLES LIKE "'.$search_table.'"');
+
+ if ($search_table_exists) {
+ $this->Conn->Query('TRUNCATE TABLE '.$search_table);
+ $select_intro = 'INSERT INTO '.$search_table.' (Relevance, ItemId, ResourceId, ItemType, EdPick) ';
+ }
+ else {
+ $select_intro = 'CREATE TABLE '.$search_table.' ENGINE = MEMORY AS ';
+ }
$id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
$fields = $this->Application->getUnitOption($event->Prefix, 'Fields');
$pick_field = isset($fields['EditorsPick']) ? $items_table.'.EditorsPick' : '0';
- $sql = ' CREATE TABLE '.$search_table.'
- SELECT '.$relevance_clause.' AS Relevance,
- '.$items_table.'.'.$id_field.' AS ItemId,
- '.$items_table.'.ResourceId AS ResourceId,
- 11 AS ItemType,
- '.$pick_field.' AS EdPick
- FROM '.$items_table.'
- '.implode(' ', $join_clauses).'
- WHERE '.$where_clause.'
- GROUP BY '.$items_table.'.'.$id_field.
- $having_clause;
-
+ $sql = $select_intro.'SELECT '.$relevance_clause.' AS Relevance,
+ '.$items_table.'.'.$id_field.' AS ItemId,
+ '.$items_table.'.ResourceId AS ResourceId,
+ 11 AS ItemType,
+ '.$pick_field.' AS EdPick
+ FROM '.$items_table.'
+ '.implode(' ', $join_clauses).'
+ WHERE '.$where_clause.'
+ GROUP BY '.$items_table.'.'.$id_field.
+ $having_clause;
$this->Conn->Query($sql);
+
+ if ( !$search_table_exists ) {
+ $sql = 'ALTER TABLE ' . $search_table . '
+ ADD INDEX (ResourceId),
+ ADD INDEX (Relevance)';
+ $this->Conn->Query($sql);
+ }
}
function getAdvancedSearchCondition($field_name, $record, $keywords, $verbs, &$highlight_keywords)
Index: core/units/categories/categories_event_handler.php
===================================================================
--- core/units/categories/categories_event_handler.php
+++ core/units/categories/categories_event_handler.php
@@ -2764,17 +2764,21 @@
}
// building final search query
+ $search_table_exists = $this->Conn->Query('SHOW TABLES LIKE "'.$search_table.'"');
+
if (!$this->Application->GetVar('do_not_drop_search_table')) {
- $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); // erase old search table if clean k4 event
+ if ( $search_table_exists ) {
+ $this->Conn->Query('TRUNCATE TABLE '.$search_table);
+ }
+
$this->Application->SetVar('do_not_drop_search_table', true);
}
- $search_table_exists = $this->Conn->Query('SHOW TABLES LIKE "'.$search_table.'"');
if ($search_table_exists) {
$select_intro = 'INSERT INTO '.$search_table.' (Relevance, ItemId, ResourceId, ItemType, EdPick) ';
}
else {
- $select_intro = 'CREATE TABLE '.$search_table.' AS ';
+ $select_intro = 'CREATE TABLE '.$search_table.' ENGINE = MEMORY AS ';
}
$edpick_clause = $this->Application->getUnitOption($event->Prefix.'.EditorsPick', 'Fields') ? $items_table.'.EditorsPick' : '0';
Index: core/units/helpers/search_helper.php
===================================================================
--- core/units/helpers/search_helper.php
+++ core/units/helpers/search_helper.php
@@ -811,8 +811,7 @@
public function ensureEmptySearchTable()
{
$search_table = $this->getSearchTable();
- $this->Conn->Query('DROP TABLE IF EXISTS ' . $search_table);
- $sql = 'CREATE TABLE ' . $search_table . ' (
+ $sql = 'CREATE TABLE IF NOT EXISTS ' . $search_table . ' (
`Relevance` decimal(8,5) DEFAULT NULL,
`ItemId` int(11) NOT NULL DEFAULT 0,
`ResourceId` int(11) DEFAULT NULL,
@@ -820,7 +819,10 @@
`EdPick` tinyint(4) NOT NULL DEFAULT 0,
KEY `ResourceId` (`ResourceId`),
KEY `Relevance` (`Relevance`)
- )';
+ ) ENGINE = MEMORY';
+ $this->Conn->Query($sql);
+
+ $sql = 'TRUNCATE TABLE ' . $search_table;
$this->Conn->Query($sql);
}
Event Timeline
Log In to Comment