简体   繁体   English

Simple.OData.Client真的很慢

[英]Simple.OData.Client really slow

I'm using Simple.OData.Client to query and update in our crm dynamics system. 我正在使用Simple.OData.Client在我们的crm动态系统中查询和更新。 But each query, insertion or update takes up to 10 seconds. 但是每次查询,插入或更新最多需要10秒钟。 It works like a charm on postman. 它就像邮递员的魅力。 That means that the server is not the problem. 这意味着服务器不是问题。

Here is my Code: 这是我的代码:

Base Class 基类

 public abstract class CrmBaseDao<T> where T : class
{
    protected ODataClient GetClient()
    {
        return new ODataClient(new ODataClientSettings(BuildServiceUrl())
        {
            Credentials = new NetworkCredential(Settings.Default.CrmUsername, Settings.Default.CrmPassword),
            IgnoreUnmappedProperties = true
        });
    }

    public async Task<IEnumerable<T>> GetAll()
    {
        var client = GetClient();
        return await client.For<T>().FindEntriesAsync();
    }

    private string BuildServiceUrl()
    {
        return Settings.Default.CrmBaseUrl + "/api/data/v8.2/";
    }
}

Derived class: 派生类:

    public void Insert(Account entity)
    {
        var task = GetClient()
            .For<Account>()
            .Set(ConvertToAnonymousType(entity))
            .InsertEntryAsync();

        task.Wait();

        entity.accountid = task.Result.accountid;
    }

    public void Update(Account entity)
    {
        var task = GetClient()
             .For<Account>()
             .Key(entity.accountid)
             .Set(ConvertToAnonymousType(entity))
             .UpdateEntryAsync();

        task.Wait();
    }

    private object ConvertToAnonymousType(Account entity)
    {
        return new
        {
            entity.address1_city,
            entity.address1_fax,
            entity.address1_line1,
            entity.address1_postalcode,
            entity.address1_stateorprovince,
            entity.he_accountnumber,
            entity.name,
            entity.telephone1,
            entity.telephone2
        };
    }

    public async Task<Account> GetByHeAccountNumber(string accountNumber)
    {
        return await GetClient().For<Account>()
            .Filter(x => x.he_accountnumber == accountNumber)
            .FindEntryAsync();
    }

The call: 电话:

 private void InsertIDocsToCrm()
    {
        foreach (var file in GetAllXmlFiles(Settings.Default.IDocPath))
        {
            var sapAccountEntity = GetSapAccountEntity(file);
            var crmAccountEntity = AccountConverter.Convert(sapAccountEntity);

            var existingAccount = crmAccountDao.GetByHeAccountNumber(crmAccountEntity.he_accountnumber);
            existingAccount.Wait();

            if (existingAccount.Result != null)
            {
                crmAccountEntity.accountid = existingAccount.Result.accountid;
                crmAccountDao.Update(crmAccountEntity);
            }
            else
                crmAccountDao.Insert(crmAccountEntity);
        }
    }

This whole function takes a very long time (30 sec+) Is there any chance to speed that up? 整个功能需要很长时间(30秒以上),是否有机会加快速度?

Additionaly it does take a lot of memory?! 另外,它确实需要很多内存吗?

Thanks 谢谢

I suspect this might have to do with a size of schema. 我怀疑这可能与架构大小有关。 I will follow the issue you opened on GitHub. 我将关注您在GitHub上打开的问题。

UPDATE. 更新。 I ran some benchmarks mocking server responses, and processing inside Simple.OData.Client took just milliseconds. 我运行了一些基准测试来模拟服务器响应,并且在Simple.OData.Client内部进行处理仅花费了几毫秒。 I suggest you run benchmarks on a server side. 我建议您在服务器端运行基准测试。 You can also try assigning metadata file references to MetadataDocument property of ODataClientSettings. 您也可以尝试将元数据文件引用分配给ODataClientSettings的MetadataDocument属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM