Show Few data into Table and run web service in background - ios

I have one problem, i fetch data from one URL and set it to Table but if data is almost 10 to 15 values. then i get data in table easily means table data populated in less time.
But if Data is almost 500 to 600 values then one have to wait till all data come as i have used ProgressView so user have to wait till all response doesn't come.
is there is any way to resolve this, to set some data earlier and then after all data that i have got afterwards.
Any help will be appreciated

you should use pagination support in your tableView and in your backend as well, please see this example:
https://easyiostechno.wordpress.com/2014/11/14/pagination-of-table-views/

Basically it's a bad practice to fetch large data at once and keep user waiting. You should ideally fetch data only when it's necessary. For your case I would suggest you to use paging mechanism.
Below is just rough idea about paging which you can use:
When you load your data from webservice, send two parameters named
PAGE_COUNT and PREVIOUS_PAGE_COUNT.
For first time send PAGE_COUNT = nuber_of_values_you_want_to_fetch_initially and PREVIOUS_PAGE_COUNT
= 0
When user scrolls down showing loader at the bottom of table and again hit webservice but with PREVIOUS_PAGE_COUNT = nuber_of_values_you_want_to_fetch_initially + PAGE_COUNT
This approach will need some modification from back-end also like checking for initial page count and then fetching next records from
database.
I hope this will help you.

Related

Delphi FireDAC: how to refresh data in cache

i need to refresh data in a TFDQuery which is in cached updates.
to simplify my problem, let's suppose my MsACCESS database is composed of 2 tables that i have to join.
LABTEST(id_test, dat_test, id_client, sample_typ)
SAMPLEType(id, SampleName)
in the Delphi application, i am using TFDConnection and 1 TFDQuery (in cached updates) in which i join the 2 tables which script is:
"SELECT T.id_test, T.dat_test, T.id_client, T.sample_typ, S.SampleName
FROM LABTEST T
left JOIN SAMPLEType S ON T.sample_typ = S.id"
in my application, i also use a DBGrid to show the result of the query.
and a button to edit the field "sample_typ", like this:
qr.Edit;
qr.FieldByName('sample_typ').AsString:=ce2.text;
qr.Post;
the edition of the 'sample_typ' field works fine but the corresponding 'sampleName' field is not changing (in the grid) after an update.
in fact it is not refreshed !
the problem is here: if i do refresh of the query, an exception is raised: "cannot refresh dataset. cached updates must be commited or canceled
and batch mode terminated before refreshing"
if i commit the updates, data will be sent to database and i don't want that, i need to keep the data in cache till the end of the operation.
also if i get out of the cache, data will be refreshed in the grid but will be sent to the database after qr.post and i don't want that.
i need to refresh data in the cache. what is the solution ?
Thanks in advance.
The issue comes down to the fact that you haven't told your UI that there is any dependency on the two fields - it clearly can't know how to do the join itself without resubmitting it so if you don't want to send the updates and reload you will have a problem.
It's not clear exactly what you are trying to do, but these two ideas may help you.
If you are not going to edit the fields in the SAMPLEType tables (S) then load the values from that table into a lookup table. You can load this into a TFDMemTable. You can use an adapter which loads from a query. Your UI controls can then show the value based on the valus looked up in your local TFDMemTable. Dependiong on the UI control this might be a 'LookupField' or some such.
You may also be able to store your main data in a TFDMemTable with an Adapter - you can specify diferent TFDCommands to read the whole recordset, refresh a record, update, insert and delete a record. The TFDCommands can act on multiple tables for joined recordsets like this. That would automatically refresh the individual record for you when you post it.

ios: when I do a pagination in UITableview

I want to do pagination in UITableView.
For example,
If I show you 20 article
Do I need to send a 20 times HTTP Request ?
=> return 1 data row
DO I need to send a 1 times HTTP Request()
=> return 20 data row
This is a little bit tricky. Probably you don't know about 'lazy loading'. This is the choice in this regard. Before saying the reasons, lets see the problems of two options you provided.
Consider 2nd option: if you want 20 articles at a times. Then you have to wait to all data of these 20 articles. If once all 20 articles downloaded successfully then only user can see a article. Otherwise, user have to wait until it download. Which makes a user boring.
Consider the 1st option: it will reduces the 2nd option problem. But it still remains other problem.if user scrolling the table cell to see a specific article then the table cell will stack because in background thread downloading continue so UI will hang.
3rd option:download 1 by 1 items with lazy loading(like Facebook ). If data comes user will see article otherwise cell will empty but UI will never stack/ hang.
You can use these method of tableview delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
When your scroll reach at 20 you can call web service, these process done again when reach 40 etc.

Updating core data performance

I'm creating an app that uses core data to store information from a web server. When there's an internet connection, the app will check if there are any changes in the entries and update them. Now, I'm wondering which is the best way to go about it. Each entry in my database has a last updated timestamp. Which of these 2 will be more efficient:
Go through all entries and check the timestamp to see which entry needs to be updated.
Delete the whole entity and re-download everything again.
Sorry if this seems like an obvious question and thanks!
I'd say option 1 would be most efficient, as there is rarely a case where downloading everything (especially in a large database with large amounts of data) is more efficient than only downloading the parts that you need.
I recently did something similiar.
I solve the problem, by assigning an unique ID and a global 'updated timestamp' and thinking about 'delta' change.
I explain better, I have a global 'latest update' variable stored in user preferences, with a default value of 01/01/2010.
This is roughly my JSON service:
response: {
metadata: {latestUpdate: 2013...ecc}
entities: {....}
}
Then, this is what's going on:
pass the 'latest update' to the web service and retrieve a list of entities
update the core data store
if everything went fine with core data, the 'latestUpdate' from the service metadata became my new 'latest update variable' stored in user preferences
That's it. I am only retrieving the needed change, and of course the web service is structured to deliver a proper list. Which is: a web service backed by a database, can deal with this matter quite well, and leave the iphone to be a 'simple client' only.
But I have to say that for small amount of data, it is still quite performant (and more bug free) to download the whole list at each request.
As per our discussion in the comments above, you can model your core data object entries with version control like this
CoreDataEntityPerson:
name : String
name_version : int
image : BinaryData
image_version : int
You can now model the server xml in the following way:
<person>
<name>michael</name>
<name_version>1</name_version>
<image>string_converted_imageData</image>
<image_version>1</image_version>
</person>
Now, you can follow the following steps :
When the response arrives and you parse it, you initially create a new object from entity and fill the data directly.
Next time, when you perform an update on the server, you increase the version count of an entry by 1 and store it.
E.g. lets say the name michael is now changed to abraham, then version count of name_version on server will be 2
This updated version count will come in the response data.
Now, while storing the data in the same object, if you find the version count to be same, then the data update of that entry can be skipped, but if you find the version count to be changed, then the update of that entry needs to be done.
This way you can efficiently perform check on each entry and perform updates only on the changed entries.
Advice:
The above approach works best when you're dealing with large amount of data updation.
In case of simple text entries for an object, simple overwrite of data on all entries is efficient enough. And this also keeps the data reponse model simple.

what is the good way to display images after successfully uploading to server, objective-c,ios

Given :
view A ( uitableView ) is used to display all images after you successfully pull them from a server via a request named getAllImages
you can also upload a new photo in view A via a top right button
My Goal :
Display a new set of images ( the new images included) on the table
What I am doing is :
send the request to server for uploading image ( i am using afnetworking to do that)
since server side is only returned "success" or failure" to me without other information. Supposed it is success, I will fire a request to get the new set of images via getAllImages
will invoke reloadData to display a new set of data on the table
I am not sure this is a good way to do it, I am still looking for the best approach to achieve this task. I dont know should I use core data in this task and how to use it.
Please give me any suggestions if you have been experiencing this task. Any comments are appreciated.
Here is what I would do:
1 - call getAllImages to show all N images
2 - take new photo
3 - display N images previously gotten from getAllImages, and 1 local image from step 2
4 - fire asynchronous request (do not specifically remember how do we do that using AFNetworking) to upload image from step 2
5 - if success code, keep N+1 images. If failure code, show only N images and remove the last one.
You can specifically reload only single row using reloadrowatindexpath, without much of a performance hit.

The timeout period elapsed prior to completion of the operation or the server is not responding

I Created A VIEW IN MY ASP.NET MVC APPLICATION.
View class retrieves a data of 6100 rows
that class is used in one of my view which fills grid with data it can also be sorted.
it will load nicely for first time then sorting also works fine but when i click on last page link it takes time and finally gives following error
The timeout period elapsed prior to completion of the operation or the server is not responding
anyone can help me please i am not getting WATS the problem
Sounds like the request time is reaching the max allowed (default in ASP.NET = 30 secs). I don't think its as the back button as much as the request is randomly taking 29 secs, 31 secs, etc.
You may want to try a pagination approach to displaying your data instead of loading 6,100 rows at once - this will reduce the load times.
Check out this link for a pagination example.
Another idea would to use page caching. But I would recommend pagination.

Resources