I'm Trying to optimize my code, and I got into a problem I don't quite understand. On every page of my web app, there will be a list of notifications much like Facebook's new ticker. So, on every request, I run this code in the beggining:

```
notification_query = db.Query(Ticker, keys_only=True)\
   .filter('friends =',self.current_user.key().name())
self._notifications_future = notification_query.run()

```

Then, where I find a good spot, I call the middle function which is:

```
notification_keys = [future.parent() for future in self._notifications_future]
self._notifications = db.get_async(notification_keys)

```

Finally I fetch them all at the end:

```
context.update({'notifications': self._notifications.get_result() })

```

Every thing works great except for this: If I call the middle function in the end of the request's function, I get this:

Dumb spot
=========

![Dumb spot](https://i.stack.imgur.com/7whHt.png)

And If I call it in what I think is an optimized spot, I get this:

Smart spot
==========

![Smart spot](https://i.stack.imgur.com/7lkZy.png)

As you can see the API usage is doubled by making this "optimization". What is going on here?

Call number 2, is the first snippet in both cases. Call number 12 in dumb spot is the second snippet, and call number 12 in the smart spot is the second snippet. This last switch, has nothing to do with the problem, I've tested it.

pd: Does google charge me for time the query is "idle"?

**UPDATE**

The problem seems to be just in the dev\_server, when I tried the same example (smart version) on appspot, I got this:

Queries on appspot
==================

![appspot](https://i.stack.imgur.com/At2cE.png)

Here everything works as expected, things that get called with **run()** or **get\_async()** don't block other stuff. As I said the issue is only in dev\_server. Still it would be nice to see this feature working on localhost, for more effective profiling.