-
Notifications
You must be signed in to change notification settings - Fork 522
Description
I've noticed 2 main problems in LiteDB usages in this project. The first one is the (very) common usage of the Table property, which unlike MongoRepository's implementation, this:
// LiteDBRepository.cs
public virtual IQueryable<T> Table => Collection.Query().ToEnumerable().AsQueryable();will always get all documents from the collection (as ToEnumerable executes), making AsQueryable() instructions occur on the machine rather than the DB. Imagine a large store having 10M products while running a liteDB instance.
The 2nd problem is the fact that LiteDB doesn't provide async methods. Which means the ToEnumerable call above blocks the calling thread.
Not me mention the usage of await Task.FromResult below that does nothing but add an async handling overhead while still blocking, but is indeed needed to implement IRepository.
// LiteDBRepository.cs
public virtual async Task<T> GetByIdAsync(string id)
{
return await Task.FromResult(GetById(id));
}Adding the two problems together might introduce a significant performance impact so i'd consider either:
- Use https://github.com/mlockett42/litedb-async to "handle" the 2nd problem. (I can create a migration PR)
- Highly endorse MongoDB usage over LiteDB.