Recent Friends

Discussion in 'iOS Programming' started by oo7ml, Jul 12, 2014.

  1. oo7ml macrumors 6502

    Joined:
    Jan 20, 2010
    #1
    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.
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Try an NSArray, which is persisted in a file.

    Look up the NSArray methods with the words "ContentsOfFile" and "writeToFile" in them.
     
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    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.
     
  4. oo7ml thread starter macrumors 6502

    Joined:
    Jan 20, 2010
    #4
    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?
     
  5. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #5
    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)
     
  6. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    Is the database on the phone or on the internet?
     
  7. oo7ml thread starter macrumors 6502

    Joined:
    Jan 20, 2010
    #7
    The database is on the internet (using parse.com)
     
  8. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #8
    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.
     
  9. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #9
    Exactly what I tried to explain
     
  10. D.T. macrumors 604

    D.T.

    Joined:
    Sep 15, 2011
    Location:
    Vilano Beach, FL
    #10
    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.
     
  11. oo7ml thread starter macrumors 6502

    Joined:
    Jan 20, 2010
    #11
    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.
     

Share This Page