Page 2 of 2

Re: Any tips or diagnostic software to check slow Jiwa?

PostPosted: Tue Jan 14, 2020 10:25 am
by SBarnes
Given there are about seven custom fields that have to be read how could you set them up as tasks and run them in parallel with something like Task.WhenAll?

Re: Any tips or diagnostic software to check slow Jiwa?

PostPosted: Tue Jan 14, 2020 1:04 pm
by Mike.Sheen
SBarnes wrote:Given there are about seven custom fields that have to be read how could you set them up as tasks and run them in parallel with something like Task.WhenAll?


Something like this:

Code: Select all
string field1;
string field2;
string field3;

List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>();
System.Threading.Tasks.Task task = System.Threading.Tasks.Task.Factory.StartNew(() => { field1 = JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValueCollection.ReadCustomFieldValue(Plugin.Manager, "IN_CustomSettingValues", "InventoryID", "SettingID", "SettingID","IN_CustomSetting", inventoryID, "MyCustomField1" ); });      
tasks.Add(task);

task = System.Threading.Tasks.Task.Factory.StartNew(() => { field2 = JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValueCollection.ReadCustomFieldValue(Plugin.Manager, "IN_CustomSettingValues", "InventoryID", "SettingID", "SettingID","IN_CustomSetting", inventoryID, "MyCustomField2" ); });      
tasks.Add(task);

task = System.Threading.Tasks.Task.Factory.StartNew(() => { field3 = JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValueCollection.ReadCustomFieldValue(Plugin.Manager, "IN_CustomSettingValues", "InventoryID", "SettingID", "SettingID","IN_CustomSetting", inventoryID, "MyCustomField3" ); });      
tasks.Add(task);

System.Threading.Tasks.Task.WaitAll(tasks.ToArray());

Re: Any tips or diagnostic software to check slow Jiwa?

PostPosted: Tue Jan 14, 2020 1:29 pm
by DannyC
Thanks Mike.

Next issue on the same plugin.
I am using the same instantiated inventory object to read the inventory.Groups collection. This isn't available in the item entity so it seems that the full inventory object serves 2 purposes in this plugin. (reading the custom fields and also reading the inventory groups).

In this case, I'll just knock up a quick SELECT statement and read the IN_GroupLink table. That'll do the trick for me.

Re: Any tips or diagnostic software to check slow Jiwa?

PostPosted: Tue Jan 14, 2020 2:23 pm
by pricerc
SBarnes wrote:Given there are about seven custom fields that have to be read how could you set them up as tasks and run them in parallel with something like Task.WhenAll?


If you only need to read them, you can use the technique I describe in https://forums.jiwa.com.au/viewtopic.php?f=25&t=1239 to create an easy-to-query view over your custom data. You could have a single, simple SQL query that gets them all, rather than firing of an individual query for each one.

Re: Any tips or diagnostic software to check slow Jiwa?

PostPosted: Tue Jan 14, 2020 3:04 pm
by SBarnes
Actually Danny is you want to get the group links in quicker way the following ORM Lite code will do it


Code: Select all
private List<JiwaServiceModel.Tables.IN_GroupLink> GetGroupLinks( JiwaFinancials.Jiwa.JiwaApplication.Manager manager)
{
            
       var dbFactory = new OrmLiteConnectionFactory(manager.Database.ConnectionString, ServiceStack.OrmLite.SqlServer2012Dialect.Provider);
      using (var db = dbFactory.Open())
      {
         return db.Select<JiwaServiceModel.Tables.IN_GroupLink> ();
                           
      }
}


Re: Any tips or diagnostic software to check slow Jiwa?

PostPosted: Tue Jan 14, 2020 5:07 pm
by Mike.Sheen
pricerc wrote:If you only need to read them, you can use the technique I describe in https://forums.jiwa.com.au/viewtopic.php?f=25&t=1239 to create an easy-to-query view over your custom data. You could have a single, simple SQL query that gets them all, rather than firing of an individual query for each one.


That's how I'd be inclined to do it also - just a single query returning each custom field value contents as a column.

Re: Any tips or diagnostic software to check slow Jiwa?

PostPosted: Wed Jan 15, 2020 5:19 pm
by DannyC
As an FYI for anyone following this thread, the users have reported that line entry is much better.

All I did was stop the full inventory instantiating, and just used
Code: Select all
string myCustomField = JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValueCollection.ReadCustomFieldValue(salesOrder.Manager,"IN_CustomSettingValues","InventoryID","SettingID", "SettingID","IN_CustomSetting",item.InventoryID, "MyCustomField" );


Furthermore with this newfound knowledge, I've replaced similar code in a few other plugins.
Big thanks to Scott & Mike.