Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

oo7ml

macrumors 6502
Original poster
Jan 20, 2010
259
0
Hi, i have built my first app which is just a very basic instant messaging app.

When you click the message button, it loads a screen with your recent friends (the last 5 people you sent a message to).

The Recent Friends list works by querying the database to see who are the last 5 people that you either sent a message to OR those who sent you a message.

I find the list sometimes takes a while to load, purely because it is querying the database for this list.

I'd like to change this feature so that it loads instantly from the iPhone memory instead of querying the database. Can anyone recommend a way to do this?

Thanks in advance for your help.
 
Try an NSArray, which is persisted in a file.

Look up the NSArray methods with the words "ContentsOfFile" and "writeToFile" in them.
 
A query that returns five rows shouldn't take very long. If it is complex then you should optimize your queries. Think about keeping a table that only has in it the last five contacts. Or adding a column that keeps the contacts in order with an index on it. Make sure the database is open before the user can tap the message button.
 
Thanks guys, i guess it depends on a persons interent connection too.

Should the recent contacts be loaded and stored into the phone memory or do you think it is ok to load them from the DB each time?
 
Thanks guys, i guess it depends on a persons interent connection too.

Should the recent contacts be loaded and stored into the phone memory or do you think it is ok to load them from the DB each time?

Only load them from the DB when the app starts.
Then add the last 5 to an array, and update that array every time. And look up the array when you refresh it. So you wont need to keep looking up in the DB, that will keep the users internet usage a bit lower and better performance
(dont forget to update the DB as well)
 
That's different. You could have some local cache of the initial data. Or you can show the UI but load the data lazily. Can a user send/receive messages from more than one device? If so then you always need to update the local data when the app launches.
 
Local storage might be a better design, but I’d be a touch interested in why the query takes so long.

I was going to say run some kind of query analyzer, but it looks like you’re using Parse.com and I don’t know what kind of tools/utilities are available[?]

How many records are we talking about? A query that’s a ‘top n where user_id = x or recipient_id = x order by date’ sort of thing should be pretty fast with proper indexes and reasonable network bandwidth.
 
Yeah it takes about 1.5 seconds on Wi Fi and about 3 on cellular which is 3 seconds too long for apps these days.

I'll have to look at caching them.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.