probr-uzh / probr-analysis

Analysis components for the probr WiFi tracking system
MIT License
14 stars 9 forks source link

Better implementation for last seen devices in live view #46

Closed sebastian-stephan closed 8 years ago

sebastian-stephan commented 9 years ago

The last seen devices in the live view are currently populated by traversing all devices and adding those which are in the different time periods (last 5 min, last hour, last day):

See live.controller.js

This is very inefficient and doesn't scale, since we query all 65k (current) devices and send them to the browser. We should query once with something like:

Device.find({
        "last_seen": {$lt: new Date(new Date().valueOf() - 1000 * 60 * 60) } }
    })
    .sort({"last_seen": -1})
    .limit(1000);

to query all devices in the last hour (also with a sensible upper limit of ~1000), and then traverse those and add them to the corresponding bucket. Or alternatively make three different queries for each bucket (might be less efficient) No need to get all 65k devices. :smirk: