更新我的RavenDB可能有一百或两百个文档(它是一个开发数据库) . 文件的大小从几K到几百K不等 . 加载主页后,发生了重大的减速,我不知道为什么 . 家庭控制器将对Raven进行一些简单的调用,大多数是通过Id加载东西 .

EDIT :经过多次清理后,我发现该问题与服务器端无关 . Fiddler表明,调用根本没有时间执行 . 但是,我认为我使用会话的异步功能的方式存在问题 .

这是Ants Performance Profiler的输出 . 谁能指出我正确的方向?或者我可以提供更多信息吗?使用ASP.NET/Autofac/Raven 2. *客户端

enter image description here

这是我的Raven存储库的样子(相关部分)

public class RavenAsyncRepository<TEntity> : IRavenAsyncRepository<TEntity> where TEntity : IAggregateRoot
{
    private readonly Func<IDocumentStore> _storeFactory;
    private readonly string _keyFormat;
    private IAsyncDocumentSession _session;

    public RavenAsyncRepository(Func<IDocumentStore> storeFactory)
    {
        _storeFactory = storeFactory;
        _keyFormat = typeof(TEntity).GetCustomAttribute<KeyFormatAttribute>().GetFormat();
    }

    private void EnsureOpenedSession()
    {
        if (_session != null) return;
        _session = _storeFactory().OpenAsyncSession();
        _session.Advanced.UseOptimisticConcurrency = true;
    }

    public async Task<IList<TEntity>> GetMany()
    {
        EnsureOpenedSession();
        return await _session.Query<TEntity>().ToListAsync();
    }

    public async Task<TEntity> GetSingle(string id)
    {
        EnsureOpenedSession();
        return await _session.LoadAsync<TEntity>(id);
    }

我相信违规的电话是:

return await _identityRepository.GetSingle(n => n.UserName == userName);

还有这个

var accounts = await _accountRepository.GetMany(n => n.UserProfiles.Any(u => u.IsEnabled && u.Name == user.UserName));