6

We are all familiar with the three dots loader of StackOverflow. Recently I found a minor bug when performing a seach on users. The search is triggered every time you stop writing and an ajax request is made with the new query.

In the following photo there are 6 concurrent requests. In mi opinion those request should be canceled before sending a new one or no requests should be made when another is still in progress. All this affects the web server performance.

requests

Also a new loader is added every time one of this requests is made making a very curious effect.

bug

3
  • 7
    That's an... unusual profile pic you caught there.
    – Mat
    Commented May 26, 2015 at 14:44
  • 1
    I didn't see that x) sorry. I was searching for john doe and turns out that there are a lot of those in stack overflow
    – devconcept
    Commented May 26, 2015 at 14:47
  • Related: meta.stackexchange.com/questions/90254/… Commented Nov 18, 2015 at 6:35

2 Answers 2

4

This is actually a symptom of a (slightly) bigger issue with the user search code: if the Ajax requests to load the filtered user list take more than 500ms to complete, the current implementation is happy to launch new requests even while there are earlier ones pending. Besides being slightly wasteful of bandwidth and server resources, it could potentially cause incorrect output if the requests complete out of order.

Anyway, this would be trivial to fix. In fact, let me post a patch (against the inline JS code used on the users page):

--- old.js  2015-07-17 16:06:03.294734128 +0300
+++ new.js  2015-07-17 16:07:12.446733344 +0300
@@ -1,5 +1,6 @@
     $(function () {
                 $("#userfilter").val("").focus().typeWatch({ highlight: true, wait: 500, captureLength: -1, callback: finished(false) });
+        var request = null;
         function finished(all) {

             var showingAll = all;
@@ -16,7 +17,8 @@

                     var spinner = $("#userfilter").addSpinnerAfter({ 'margin-left': "8px", 'margin-bottom': '-4px' }).next();

-                    $.ajax({
+                    if (request) request.abort();
+                    request = $.ajax({
                         url: url,
                         data: {
                             search: search,

That's two extra lines (var request = null; and if (request) request.abort();) and one change to an existing line (adding request = before $.ajax({).

This patch will cause any pending Ajax requests for filtered user lists to be aborted whenever a new request is launched. As a side effect, it also gets rid of the extra spinners (since aborting the request triggers the complete callback, which removes the spinner).

Ps. I'll leave fixing the similar bug on the tags page as an exercise. (This one isn't so visually conspicuous, since there's no spinner.) Or you could just borrow the code from SOUP, which includes a client-side fix for both versions of this bug as of v1.32. ;-)

2

Solution:

Don't stop so frequently ;)

6
  • what's the point to allow people from posting bugs if you are never gonna fix them. The problem is not only visual. It adds more load to the server for no reason and this is the way normally people search. You ask me to stop and I will of course but don't expect your other users to do that. SO is a place where programmers gather, every programmer groan when they see that. I'm sure you people have the talent to fix that tiny problem.
    – devconcept
    Commented Jun 4, 2015 at 13:48
  • 2
    This is about priorities. This is a small bug that has very little effect on the site and its users (also - happens rarely - I can't trigger it at all, since the response times from the server are very quick for me). I'd rather fix higher priority bugs - don't you?
    – Oded StaffMod
    Commented Jun 4, 2015 at 13:50
  • @Oded: Does this at least have enough priority for someone to apply a patch? Commented Jul 17, 2015 at 13:16
  • 1
    I'll take a look on Monday, @Ilmari
    – Oded StaffMod
    Commented Jul 17, 2015 at 17:01
  • @Oded: It's Monday now. Have you had a chance to take a look at this yet? :) Commented Nov 23, 2015 at 10:04
  • 1
    @IlmariKaronen - errr. With you in the next build (also on Tags page)
    – Oded StaffMod
    Commented Nov 23, 2015 at 10:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .