From 1fe9ffd775761d9727ed745c9a7a97bed8e57559 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <feedback@starbeamrainbowlabs.com>
Date: Mon, 28 Nov 2016 14:05:23 +0100
Subject: [PATCH] Make dynaimc page suggestor faster. Fixes #124.

---
 build/index.php            |  4 +++-
 module_index.json          | 48 +++++++++++++++++++-------------------
 modules/feature-search.php |  4 +++-
 3 files changed, 30 insertions(+), 26 deletions(-)
 mode change 100755 => 100644 build/index.php

diff --git a/build/index.php b/build/index.php
old mode 100755
new mode 100644
index 81ca4ef..7b2a10d
--- a/build/index.php
+++ b/build/index.php
@@ -2647,12 +2647,14 @@ window.addEventListener("load", function(event) {
 			}
 			
 			// Add the new suggestions to the datalist
+			var optionsFrag = document.createDocumentFragment();
 			suggestions.forEach(function(suggestion) {
 				var suggestionElement = document.createElement("option");
 				suggestionElement.value = suggestion.pagename;
 				suggestionElement.dataset.distance = suggestion.distance;
-				dataList.appendChild(suggestionElement);
+				optionsFrag.appendChild(suggestionElement);
 			});
+			dataList.appendChild(optionsFrag);
 		});
 	});
 });
diff --git a/module_index.json b/module_index.json
index b42b28c..42b4490 100755
--- a/module_index.json
+++ b/module_index.json
@@ -5,7 +5,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds a utility action (that anyone can use) called hash that hashes a given string. Useful when changing a user's password.",
         "id": "action-hash",
-        "lastupdate": 1465757909,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -14,7 +14,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Exposes Pepperminty Wiki's new page protection mechanism and makes the protect button in the 'More...' menu on the top bar work.",
         "id": "action-protect",
-        "lastupdate": 1465751051,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -23,7 +23,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds a 'raw' action that shows you the raw source of a page.",
         "id": "action-raw",
-        "lastupdate": 1476906745,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -32,7 +32,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds a sidebar to the left hand side of every page. Add '$settings->sidebar_show = true;' to your configuration, or append '&sidebar=yes' to the url to enable. Adding to the url sets a cookie to remember your setting.",
         "id": "extra-sidebar",
-        "lastupdate": 1450704211,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -41,7 +41,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "The module everyone has been waiting for! Adds a web based gui that lets mods change the wiki settings.",
         "id": "feature-guiconfig",
-        "lastupdate": 1477824489,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -50,7 +50,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds the ability to keep unlimited page history, limited only by your disk space. Note that this doesn't store file history (yet). Currently depends on feature-recent-changes for rendering of the history page.",
         "id": "feature-history",
-        "lastupdate": 1465757909,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -59,7 +59,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds recent changes. Access through the 'recent-changes' action.",
         "id": "feature-recent-changes",
-        "lastupdate": 1478108942,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -68,7 +68,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds support for redirect pages. Uses the same syntax that Mediawiki does.",
         "id": "feature-redirect",
-        "lastupdate": 1452949822,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -77,7 +77,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
         "id": "feature-search",
-        "lastupdate": 1479648436,
+        "lastupdate": 1480338195,
         "optional": false
     },
     {
@@ -86,7 +86,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds the ability to upload files to Pepperminty Wiki. Uploaded files act as pages and have the special 'File\/' prefix.",
         "id": "feature-upload",
-        "lastupdate": 1479634619,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -95,7 +95,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds the credits page. You *must* have this module :D",
         "id": "page-credits",
-        "lastupdate": 1472230366,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -104,7 +104,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds a debug action for administrator use only that collects a load of useful information to make reporting bugs easier.",
         "id": "page-debug-info",
-        "lastupdate": 1465815112,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -113,7 +113,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds an action to allow administrators to delete pages.",
         "id": "page-delete",
-        "lastupdate": 1465837295,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -122,7 +122,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
         "id": "page-edit",
-        "lastupdate": 1478354728,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -131,7 +131,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds a page that you can use to export your wiki as a .zip file. Uses $settings->export_only_allow_admins, which controls whether only admins are allowed to export the wiki.",
         "id": "page-export",
-        "lastupdate": 1472230366,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -140,7 +140,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds a rather useful help page. Access through the 'help' action. This module also exposes help content added to Pepperminty Wiki's inbuilt invisible help section system.",
         "id": "page-help",
-        "lastupdate": 1472230366,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -149,7 +149,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds a page that lists all the pages in the index along with their metadata.",
         "id": "page-list",
-        "lastupdate": 1472230366,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -158,7 +158,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds a pair of actions (login and checklogin) that allow users to login. You need this one if you want your users to be able to login.",
         "id": "page-login",
-        "lastupdate": 1472230366,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -167,7 +167,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds an action to let users user out. For security reasons it is wise to add this module since logging in automatically opens a session that is valid for 30 days.",
         "id": "page-logout",
-        "lastupdate": 1466011660,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -176,7 +176,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds an action to allow administrators to move pages.",
         "id": "page-move",
-        "lastupdate": 1480101990,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -185,7 +185,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds an update page that downloads the latest stable version of Pepperminty Wiki. This module is currently outdated as it doesn't save your module preferences.",
         "id": "page-update",
-        "lastupdate": 1476906745,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -194,7 +194,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Allows you to view pages. You really should include this one.",
         "id": "page-view",
-        "lastupdate": 1478463906,
+        "lastupdate": 1480337431,
         "optional": false
     },
     {
@@ -203,7 +203,7 @@
         "author": "Johnny Broadway & Starbeamrainbowlabs",
         "description": "The *old* default parser for Pepperminty Wiki. Based on Johnny Broadway's Slimdown (with more than a few modifications). This parser's features are documented in the help page. Superceded by a customised extension of parsedown extra.",
         "id": "parser-default-old",
-        "lastupdate": 1458824880,
+        "lastupdate": 1480337431,
         "optional": true
     },
     {
@@ -212,7 +212,7 @@
         "author": "Emanuil Rusev & Starbeamrainbowlabs",
         "description": "An upgraded (now default!) parser based on Emanuil Rusev's Parsedown Extra PHP library (https:\/\/github.com\/erusev\/parsedown-extra), which is licensed MIT. Please be careful, as this module adds some weight to your installation, and also *requires* write access to the disk on first load.",
         "id": "parser-parsedown",
-        "lastupdate": 1478204933,
+        "lastupdate": 1480337431,
         "optional": false
     }
 ]
\ No newline at end of file
diff --git a/modules/feature-search.php b/modules/feature-search.php
index bd7aad8..5054dd1 100755
--- a/modules/feature-search.php
+++ b/modules/feature-search.php
@@ -287,12 +287,14 @@ window.addEventListener("load", function(event) {
 			}
 			
 			// Add the new suggestions to the datalist
+			var optionsFrag = document.createDocumentFragment();
 			suggestions.forEach(function(suggestion) {
 				var suggestionElement = document.createElement("option");
 				suggestionElement.value = suggestion.pagename;
 				suggestionElement.dataset.distance = suggestion.distance;
-				dataList.appendChild(suggestionElement);
+				optionsFrag.appendChild(suggestionElement);
 			});
+			dataList.appendChild(optionsFrag);
 		});
 	});
 });
