This is a migrated thread and some comments may be shown as answers.

[Solved] insert data - time taking too long

2 Answers 114 Views
Data Storage for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kieran C
Top achievements
Rank 1
Kieran C asked on 25 Sep 2014, 06:04 PM

Hi,

I'm having a problem on the length of time it is taking to insert data to my local telerik storage.  I have about 12,000 records in 'items_clients' but its taking me about 40 minutes to insert the records with my 'insertRows_clients' method.  

How can I speed up the data insert...is there some other way I should write the below? 

Thanks


Dim items_clients = Await Azure_clients_dataPull() 

For Each class_client As c_ClientsAg In items_clients
            insertRows_clients(class_client)
        Next


Sub insertRows_clients(ByVal _results As c_ClientsAg)

        Dim context = New Telerik.Storage.Extensions.Context("HandheldsK3_DB", Telerik.Storage.Extensions.DatabaseLocation.Local)
        context.Insert(Of c_ClientsAg)(New c_ClientsAg() With {.ID = _results.ID, .a_id = _results.a_id, .account_name = _results.account_name,
     .address = _results.address, .place = _results.place, .province = _results.province, .last_paydate = _results.last_paydate,
                                                                                                .paid_amount = _results.paid_amount})

        context.SaveChanges()
        context.CloseDatabase()

End Sub

2 Answers, 1 is accepted

Sort by
0
Bulent
Telerik team
answered on 26 Sep 2014, 10:15 AM
Hi Kieran,

Thank you for using Telerik Data Storage!

I checked your source code and will suggest some code optimizations that should improve the execution time. As I see you call 12000 times a method insertRows_clients and in this method you create a context object , insert new object of type c_ClientsAg , save changes to the local database and close the database.
As a result you have 12000 new context objects created and destroyed , 12000 database open/close operations, and 12000  new objects explicitly created for data of interest that you receive as a parameter of method. It is better to merge the code and minimize redundant and time consuming operations as you see in the snippet bellow 


Dim items_clients = Await Azure_clients_dataPull()
 
Sub insertRows
   '1. Create only one context and use it for all operations
   Dim context = New Telerik.Storage.Extensions.Context("HandheldsK3_DB",      Telerik.Storage.Extensions.DatabaseLocation.Local)
 
   '2. for each record just insert it to local cache
   For Each class_client As c_ClientsAg In items_clients
      context.Insert(Of c_ClientsAg)(class_client)
   Next
 
   '3. save all changes to the database
   context.SaveChanges()
   context.CloseDatabase()
 
End Sub

I hope this will reduce the execution time significantly.
Please, inform me of the results and let me know if you have further questions.

Regards,
Bulent
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kieran C
Top achievements
Rank 1
answered on 26 Sep 2014, 12:59 PM
Bulent,

Thanks for your advise...that made a huge time saving. Down to less than a minute now.

Thanks for that...much appreciated.
Tags
Data Storage for XAML
Asked by
Kieran C
Top achievements
Rank 1
Answers by
Bulent
Telerik team
Kieran C
Top achievements
Rank 1
Share this question
or