Monday, December 22, 2008

Appending new items in JSON arrays with javascript

I decided to blog about this because it was a question that I struggled to solve and I couldn't find any material that gives the answer via google. To add a item to the end of a array in a JSON object, we need to take advantage of the length attribute of it. It is clearer to demonstrate this with code, like this piece of javascript:
json_data = {
    "some_array":[],
};

json_data.some_array[json_data.some_array.length] = new_item;

Wednesday, December 17, 2008

Google App Engine's real indexing limit

5000, that the number you are looking for. I tried to fill up a db.ListProperty(int) as much as I could. The SDK stopped working and started complaining about me having too much to be indexed at this point, 5000. So if you have more than 5000 entities to index in a ListProperty, get around. I came up with a solution where you use a db.ListProperty(db.Key) to hold the keys of the actual ListProperty(s) you use to store stuff. And then make some special interface for it so that it loop through its parts automatically. Implementing such kind of interface, including a reading method, a saving method and a deleting method took up about 70 lines of code, empty lines included. And then I have no limits on GAE's indexing any more!