I have an iPhone app syncing with a website using a webservice. The sync procedure I'm using is the following:
- Send items that need to sync from iPhone to website
- Add items to website MySql database
- Send back items that need to sync from website to iPhone
- Add items on iPhone Sqlite database
All this is done using one request to the server. Often the user just have a few items (<20) to sync but sometimes a user might have 2000 items to sync. Adding 2000 items to a MySql database can take some time. I'm using transactions and commit on the website when adding the items, something like this:
mysqlTransaction.BeginTransaction();
foreach item sent from iPhone
{
mysql.CommandText = //Sql query
mysql.ExecuteNonQuery();
}
mysqlTransaction.Commit();
Sometimes when a user have a lot of items to add, this can take a veeery long time. My idea is therefore to change the sync procedure a little bit and instead of using one large request I divide the request into chunks, maybe sending and recieiving 50 items at a time. This will cause more but faster requests. What are your ideas on this? How would you solve it? Is it the right thing to use transactions and commit on the server?