derbyjs / racer

Realtime model synchronization engine for Node.js
1.19k stars 118 forks source link

Query only returns first document #140

Closed switz closed 11 years ago

switz commented 11 years ago

For some reason, this query only returns the first object in the array and the rest are undefined.

[ { approved: true,
    audioOnly: false,
    clicks: 2,
    day: 20,
    delete: 0,
    id: 4fb0694fdd78bc5ad3047e81,
    ip: '149.119.199.157',
    month: 6,
    name: 'Phish - "Brother" Father\'s Day 06.20.10 Opener (w/ kids in tub)',
    number: 1,
    rating: 0,
    seconds: 183,
    showid: 1268786603,
    songname: 'Brother',
    thumb: 'http://i.ytimg.com/vi/ZEFXH9ZtRoI/0.jpg',
    time: 1297157590,
    user: 'kikimartini',
    venue: 'Saratoga Performing Arts Center',
    video: 'http://www.youtube.com/watch?v=ZEFXH9ZtRoI',
    viewcount: 5142,
    year: 2010 },
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  ...]

Using godbox, I can see that there are in fact quite a few documents that fit this query. screen shot 2013-06-05 at 12 01 53 pm

Any idea why this might be happening? I'm not utilizing any access control yet. Thanks

Edit: For more info, I notice sometimes it returns partial arrays and sometimes it returns empty arrays. Is it possible that the igor tool didn't import my mongo data to redis properly?

Edit2: It appears to be consistently on each return, implying that it has little to do with the database interaction and more to do with missing or incomplete data. I assume igor didn't import all of my data to redis - which must mean that godbox runs mostly off of mongo.

(master)igor dsaewitz$ coffee itsalive.coffee -r 1 --db phishvids
collections [ 'sessions', 'setlists', 'system.users', 'videos', 'years' ]
system.users DOCS 1
years DOCS 20
sessions DOCS 2277
setlists DOCS 1589
videos DOCS 12277
all done
nateps commented 11 years ago

Godbox is driven by ShareJS directly, and racer sits on top of ShareJS. Thus, they should be seeing the same results. In both cases, queries come from MongoDB, but the data also needs to be in Redis to work properly.

I suspect this might be related to a bug in ShareJS that we fixed last night involving fetching a query and the documents in the query. Try installing ShareJS from the latest on GitHub to see if that helps:

$ cd ~/your_project/node_modules/derby/node_modules/racer/
$ npm install git://github.com/share/ShareJS.git#rewrite
switz commented 11 years ago

Hm, that didn't work - unfortunately.

Here's what I've noticed – some weird behavior that I can't explain. If I breakpoint on this console.log, the objects in the array show up as undefined, except for the first doc.

screen shot 2013-06-05 at 2 36 19 pm

However, once I click through that breakpoint and inspect that element again, the array eventually becomes fully hydrated: screen shot 2013-06-05 at 2 33 39 pm

Is it possible that sharejs thinks the operation is complete after finding the first document, instead of waiting for all of the documents to be found?

switz commented 11 years ago

I should add that this appears to only happen in nested queries. When running it outside of the other query's callback it works as expected.

nateps commented 11 years ago

Yeah, this is definitely a bug. Working on it. For now, just use subscribe, which doesn't seem to have the same problem.

nateps commented 11 years ago

Fixed: https://github.com/codeparty/racer/commit/bc856a34fa3edde3dde350f3aaa9d0a1989343e6