kazu2012 / persevere-framework

Automatically exported from code.google.com/p/persevere-framework
0 stars 0 forks source link

Possible bug in server.js/slice() #241

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Expected 19 results when slicing [0:19] getting back 38 entries, all of which 
are duplicates,
you can see below:

curl -g --header 'content-type: application/json' 
"http://localhost:4155/incident_incident/[?
reporter[0]=/tenancy_user/33&urgency=5][\id]" | grep '"id"'  | wc -l
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9510    0  9510    0     0  24161      0 --:--:-- --:--:-- --:--:-- 59785
19

curl -g --header 'content-type: application/json' 
"http://localhost:4155/incident_incident/[?
reporter[0]=/tenancy_user/33&urgency=5][\id][0:18]" | grep '"id"'  | wc -l
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  8989    0  8989    0     0  29387      0 --:--:-- --:--:-- --:--:-- 98112
18

curl -g --header 'content-type: application/json' 
"http://localhost:4155/incident_incident/[?
reporter[0]=/tenancy_user/33&urgency=5][\id][0:19]" | grep '"id"'  | wc -l
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
0

curl -s -g --header 'content-type: application/json' 
"http://localhost:4155/incident_incident/[?
reporter[0]=/tenancy_user/33&urgency=5][\id]" | grep '"id"' 
{"id":"291",
{"id":"290",
{"id":"289",
{"id":"288",
{"id":"287",
{"id":"286",
{"id":"285",
{"id":"284",
{"id":"272",
{"id":"270",
{"id":"269",
{"id":"216",
{"id":"170",
{"id":"163",
{"id":"162",
{"id":"157",
{"id":"150",
{"id":"126",
{"id":"125",

curl -s -g --header 'content-type: application/json' 
"http://localhost:4155/incident_incident/[?
reporter[0]=/tenancy_user/33&urgency=5][\id][0:18]" | grep '"id"' 
{"id":"291",
{"id":"290",
{"id":"289",
{"id":"288",
{"id":"287",
{"id":"286",
{"id":"285",
{"id":"284",
{"id":"272",
{"id":"270",
{"id":"269",
{"id":"216",
{"id":"170",
{"id":"163",
{"id":"162",
{"id":"157",
{"id":"150",
{"id":"126",

curl -s -g --header 'content-type: application/json' 
"http://localhost:4155/incident_incident/[?
reporter[0]=/tenancy_user/33&urgency=5][/id][0:18]" | grep '"id"' 
{"id":"125",
{"id":"126",
{"id":"150",
{"id":"157",
{"id":"162",
{"id":"163",
{"id":"170",
{"id":"216",
{"id":"269",
{"id":"270",
{"id":"272",
{"id":"284",
{"id":"285",
{"id":"286",
{"id":"287",
{"id":"288",
{"id":"289",
{"id":"290",

curl -s -g --header 'content-type: application/json' 
"http://localhost:4155/incident_incident/[?
reporter[0]=/tenancy_user/33&urgency=5][0:18]" | grep '"id"' 
{"id":"125",
{"id":"126",
{"id":"150",
{"id":"157",
{"id":"162",
{"id":"163",
{"id":"170",
{"id":"216",
{"id":"269",
{"id":"270",
{"id":"272",
{"id":"284",
{"id":"285",
{"id":"286",
{"id":"287",
{"id":"288",
{"id":"289",
{"id":"290",

Duplicate entries:
curl -s -g --header 'content-type: application/json' 
"http://localhost:4155/incident_incident/[?
reporter[0]=/tenancy_user/33&urgency=5][0:19]" | grep '"id"'  | wc -l
38

$ curl -s -g --header 'content-type: application/json' 
"http://localhost:4155/incident_incident/[?reporter[0]=/tenancy_user/33&urgency=
5][0:18][\id]" 
| grep '"id"'  | wc -l
18

sorted and uniq'd:

$ curl -s -g --header 'content-type: application/json' 
"http://localhost:4155/incident_incident/[?reporter[0]=/tenancy_user/33&urgency=
5][0:19]"  | 
grep '"id"' | sort -u
{"id":"125",
{"id":"126",
{"id":"150",
{"id":"157",
{"id":"162",
{"id":"163",
{"id":"170",
{"id":"216",
{"id":"269",
{"id":"270",
{"id":"272",
{"id":"284",
{"id":"285",
{"id":"286",
{"id":"287",
{"id":"288",
{"id":"289",
{"id":"290",
{"id":"291",

curl -s -g --header 'content-type: application/json' 
"http://localhost:4155/incident_incident/[?
reporter[0]=/tenancy_user/33&urgency=5][0:19]"  | grep '"id"' | sort -u | wc -l
19

Original issue reported on code.google.com by rrm...@gmail.com on 7 Sep 2009 at 11:53

GoogleCodeExporter commented 8 years ago
I looked at the code quick and think that this might be just a lack of a return 
in
server.js/slice():
                        if(step < 5){
                                // do an iterator friendly
                                i = 0;
                                for each(var item in obj){
                                        if(i >= end){
                                                return results;
                                        }
                                        if(i >= start && i % step == 0){
                                                results.push(item);
                                        }
                                        i++;
                                        if(i > maxIterations){
                                                throwMaxIterations();
                                        }
                                }
                                // return the results after this iterator friendly run?
                                return results;
                        }

Original comment by beau.cro...@gmail.com on 8 Sep 2009 at 8:00

GoogleCodeExporter commented 8 years ago
I checked in a fix for this, do you want to check to see if it fixes it?

Original comment by kris...@gmail.com on 10 Sep 2009 at 12:23