Browse Source

! There really is no good reason now not to be ORDER BY LENGTH(code) for smileys. MySQL supports it now after those rocky days when we couldn't rely on it, PGSQL and SQLite seem to support it as far as I can tell, it's also cached so the filesort isn't the killer it could necessarily be. Let's do this and fix #1091 while we're at it.

Signed-off-by: Peter Spicer <sleeping@myperch.org>
Peter Spicer 11 years ago
parent
commit
5e7d98700a
2 changed files with 3 additions and 47 deletions
  1. 1 46
      Sources/ManageSmileys.php
  2. 2 1
      Sources/Subs.php

+ 1 - 46
Sources/ManageSmileys.php

@@ -164,10 +164,6 @@ function EditSmileySettings($return_config = false)
 		// Validate the smiley set name.
 		$_POST['smiley_sets_default'] = empty($smiley_context[$_POST['smiley_sets_default']]) ? 'default' : $_POST['smiley_sets_default'];
 
-		// Make sure that the smileys are in the right order after enabling them.
-		if (isset($_POST['smiley_enable']))
-			sortSmileyTable();
-
 		call_integration_hook('integrate_save_smiley_settings');
 
 		saveDBSettings($config_vars);
@@ -894,9 +890,6 @@ function EditSmileys()
 					)
 				);
 			}
-
-			// Sort all smiley codes for more accurate parsing (longest code first).
-			sortSmileyTable();
 		}
 
 		cache_put_data('parsing_smileys', null, 480);
@@ -1696,9 +1689,6 @@ function ImportSmileys($smileyPath)
 			array('id_smiley')
 		);
 
-		// Make sure the smiley codes are still in the right order.
-		sortSmileyTable();
-
 		cache_put_data('parsing_smileys', null, 480);
 		cache_put_data('posting_smileys', null, 480);
 	}
@@ -2003,39 +1993,4 @@ function list_getMessageIcons($start, $items_per_page, $sort)
 	return $message_icons;
 }
 
-/**
- * This function sorts the smiley table by code length,
- * it is needed as MySQL withdrew support for functions in order by.
- * @todo is this ordering itself needed?
- */
-function sortSmileyTable()
-{
-	global $smcFunc;
-
-	db_extend('packages');
-
-	// Add a sorting column.
-	$smcFunc['db_add_column']('{db_prefix}smileys', array('name' => 'temp_order', 'size' => 8, 'type' => 'mediumint', 'null' => false));
-
-	// Set the contents of this column.
-	$smcFunc['db_query']('set_smiley_order', '
-		UPDATE {db_prefix}smileys
-		SET temp_order = LENGTH(code)',
-		array(
-		)
-	);
-
-	// Order the table by this column.
-	$smcFunc['db_query']('alter_table_smileys', '
-		ALTER TABLE {db_prefix}smileys
-		ORDER BY temp_order DESC',
-		array(
-			'db_error_skip' => true,
-		)
-	);
-
-	// Remove the sorting column.
-	$smcFunc['db_remove_column']('{db_prefix}smileys', 'temp_order');
-}
-
-?>
+?>

+ 2 - 1
Sources/Subs.php

@@ -2415,7 +2415,8 @@ function parsesmileys(&$message)
 			{
 				$result = $smcFunc['db_query']('', '
 					SELECT code, filename, description
-					FROM {db_prefix}smileys',
+					FROM {db_prefix}smileys
+					ORDER BY LENGTH(code) DESC',
 					array(
 					)
 				);