From 164e3495f60f1a16f775099ab5ee872b129b73aa Mon Sep 17 00:00:00 2001 From: aashna27 Date: Sat, 9 Mar 2019 06:51:50 +0530 Subject: [PATCH] Added debounce for typeahead search optimization (#4904) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added debounce for typeahead search optimization * Update README.md (#4883) The "What makes this project different" section had several long sentences which were difficult to understand. I tried to fix this by breaking the sentences down into smaller more concise sentences. * convert chars to unicode (#4901) * fixes for map module (#4909) * fixes for map module * yarn.lock update * updated yarn.lock (#4911) * updated yarn.lock * tweak * Remove useless variable assignment (#4885) * Simplify username generation * Use status module * Tiny fix * Fix indentation * Made moderate buttons to appear on the same line (#4913) * Made moderate buttons to appear on the same line * Removed break tag. * Clean up (#4902) * Clean up with Rubocop * More cleanup * Excluse views * Small refactor * More clean up * Clean up * Fix conflict * Tiny fix * Follow tag asynchronously (#4587) * Follow tag asynchronously Added link to manage subscriptions Add precondition failed http error code cleanup codeclimate fix Fix typo change remove data-remote Preserve code for non xhr requests Seperate JS and html Codeclimate fix Code Climate fixes Updated tests * Remove pre-compilation of async.js * pre compilation of js assets * cc fix try * Move verification link (#4786) * Move verification link * Change link to text * Remove unnecessary message * popover works, styling is still not showing under elements but is und… (#4906) * popover works, styling is still not showing under elements but is under.btn-default * copied yml file back in * First timer tag script (#4878) * First timer tag script * migration for attaching first-time-poster * change migration bump version to 5.1 * Update schema.rb.example * Consolidating ranges and stats (#4887) * restyle range page to be a partial * remove static stats * merge range and main stats * render range in main stats * fix failing range test * add questions vs answers graph * add go back and further buttons * minor fixes * Change contribution graph making method Change method to create graph based on the range given * fix failing test and code climate issues * remove commented code and indent * remove stats_nav partial * add contribution graph tests * review requests implemetation * move tag graph button (#4921) * move tag graph button * Update _user_controls.html.erb * Added reply by tweet feature (#3175) * Added reply by tweet feature * Updated schedule.rb file * Finalized reply-by-tweet * Corrected schema version * Minor change * Added reply_by_tweet doc * Minor changes * Added twitter gem * Minor changes * Added Environment variables in Docker * Added summery in Doc file * Corrected schema version * Added some documentation * Added some documentation * Migration timestamp changed * Changed migration * Minor change * Minor changes * Added rake to general gem list * Added bundle exec for rake/rails tasks in schedule.rb * Added path env variable * MINOR CHANGE * MINOR CHANGE * MINOR CHANGE * MINOR CHANGE * Added print statement to check print * Minor change * Minor change * Changed whenever config * Minor change * Completed reply by tweet feature * Minor change * Minor change * Added gemfile.lock * Update comment.rb * Added gemfile.lock * Minor changes * Minor changes * Minor changes * Minor changes * Add more relevant search results (#4848) * add helper functions * Modify controller to take extra results * add dict file * add more objects * refactor code and add tests * cc fix * change numbers to account for additions in fixtures * fix tests * remove unused include * code quality fixes * tab fix * changing implementation ideas, removal of unnecessary code * newline fix * cc fix * cc space inside brackets fix * modify query to get rid of redundant words * reduce word to root then tranform * Change file name * chore: update README.md (#4926) Fixes task mentioned in issue #4749 * Bump cytoscape from 3.4.2 to 3.5.0 (#4929) Bumps [cytoscape](https://github.com/cytoscape/cytoscape.js) from 3.4.2 to 3.5.0. - [Release notes](https://github.com/cytoscape/cytoscape.js/releases) - [Commits](https://github.com/cytoscape/cytoscape.js/compare/v3.4.2...v3.5.0) Signed-off-by: dependabot[bot] * Tiny fix (#4933) * Tiny fix * Rubocop * Update 20190301075323_add_first_tag_poster.rb * updates (#4851) * fix for wiki update (#4942) * fixes, extend to title suggestions * extended to atwho --- .eslintrc | 3 +++ app/assets/javascripts/application.js | 1 + app/assets/javascripts/atwho_autocomplete.js | 8 ++++---- app/assets/javascripts/restful_typeahead.js | 5 ++--- app/views/editor/rich.html.erb | 4 ++-- package.json | 1 + yarn.lock | 5 +++++ 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.eslintrc b/.eslintrc index 9faa37508e..de99afaf3e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,6 +9,9 @@ env: jquery: true node: true +parseOptions: + sourceType: module + # http://eslint.org/docs/rules/ rules: # Possible Errors diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index d7f2a1253c..d406268156 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -15,6 +15,7 @@ // //= require jquery //= require jquery_ujs +//= require debounce/index.js //= require bootstrap/dist/js/bootstrap.min.js //= require bootstrap-3-typeahead/bootstrap3-typeahead.min.js //= require bootstrap-datepicker/dist/js/bootstrap-datepicker.js diff --git a/app/assets/javascripts/atwho_autocomplete.js b/app/assets/javascripts/atwho_autocomplete.js index 65684e1ea5..4ffe8dc8c1 100644 --- a/app/assets/javascripts/atwho_autocomplete.js +++ b/app/assets/javascripts/atwho_autocomplete.js @@ -5,13 +5,13 @@ at: "@", delay: 400, callbacks: { - remoteFilter: function(query, callback) { + remoteFilter: debounce(function(query, callback) { $.getJSON("/api/srch/profiles?query=" + query + "&sort_by=recent&field=username", {}, function(data) { if (data.hasOwnProperty('items') && data.items.length > 0) { callback(data.items.map(function(i) { return i.doc_title })); } }); - } + }, 200) }, limit: 20 }, @@ -19,13 +19,13 @@ at: "#", delay: 400, callbacks: { - remoteFilter: function(query, callback) { + remoteFilter: debounce(function(query, callback) { if (query != ''){ $.post('/tag/suggested/' + query, {}, function(response) { callback(response.map(function(tagnames){ return tagnames })); }); } - } + }, 200) }, limit: 20 }, diff --git a/app/assets/javascripts/restful_typeahead.js b/app/assets/javascripts/restful_typeahead.js index b4e7a0a33e..fe168b40b9 100644 --- a/app/assets/javascripts/restful_typeahead.js +++ b/app/assets/javascripts/restful_typeahead.js @@ -10,16 +10,15 @@ $(function() { var typeahead = $(el).typeahead({ items: 10, minLength: 3, - delay: 350, showCategoryHeader: true, autoSelect: false, - source: function (query, process) { + source: debounce(function (query, process) { var encoded_query = encodeURIComponent(query); var qryType = $(el).attr('qryType'); return $.getJSON('/api/srch/' + qryType + '?query=' + encoded_query, function (data) { return process(data.items); },'json'); - }, + }, 350), highlighter: function (text, item) { return item.doc_title; }, diff --git a/app/views/editor/rich.html.erb b/app/views/editor/rich.html.erb index de091cda7c..84addd2706 100644 --- a/app/views/editor/rich.html.erb +++ b/app/views/editor/rich.html.erb @@ -328,7 +328,7 @@ titleModule: { suggestRelated: true, - fetchRelated: function(show) { + fetchRelated: debounce(function(show) { $.getJSON("/api/srch/notes?query=" + editor.titleModule.value(), function(response) { /* API provides: {"items":[{ @@ -353,7 +353,7 @@ show(formatted); } }); - } + }, 350) }, tagsModule: { diff --git a/package.json b/package.json index 1ad5e28151..7a89a840f2 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "bootstrap-tokenfield": "^0.12.0", "chart.js": "^2.7.0", "cytoscape": "^3.5.0", + "debounce": "^1.2.0", "file-saver": "^2.0.0", "font-awesome": "^4.5.0", "i18n-js": "^3.2.1", diff --git a/yarn.lock b/yarn.lock index f37e91ce34..f9cf705fd4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1014,6 +1014,11 @@ dateformat@1.0.2-1.2.3: resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-1.0.2-1.2.3.tgz#b0220c02de98617433b72851cf47de3df2cdbee9" integrity sha1-sCIMAt6YYXQztyhRz0fePfLNvuk= +debounce@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/debounce/-/debounce-1.2.0.tgz#44a540abc0ea9943018dc0eaa95cce87f65cd131" + integrity sha512-mYtLl1xfZLi1m4RtQYlZgJUNQjl4ZxVnHzIR8nLLgi4q1YT8o/WM+MK/f8yfcc9s5Ir5zRaPZyZU6xs1Syoocg== + debug@0.7.4: version "0.7.4" resolved "https://registry.yarnpkg.com/debug/-/debug-0.7.4.tgz#06e1ea8082c2cb14e39806e22e2f6f757f92af39"