Skip to content

Commit

Permalink
Hotfix: Move sorting from Mongo Queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Wadhams committed Jun 6, 2018
1 parent bbab9d4 commit fda74e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async Task<IEnumerable<T>> IQueryStore.GetAllByTypeAsync<T>(string typeName)
var filter = Builders<T>.Filter.Eq(d => d.Type, typeName);

var collection = GetCollection<T>();
var result = await RetryPolicy.ExecuteAsync(context => collection.FindAsync(filter), new Context(nameof(IQueryStore.GetAllByTypeAsync)));
var result = await RetryPolicy.ExecuteAsync(context => collection.FindAsync(filter), new Context(nameof(IQueryStore.GetAllByTypeAsync)));

return result?.ToEnumerable();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
using Esfa.Recruit.Vacancies.Client.Infrastructure.Exceptions;
using Microsoft.Extensions.Logging;
using Polly;
using System.Linq;

namespace Esfa.Recruit.Vacancies.Client.Infrastructure.Repositories
{
internal sealed class MongoDbVacancyRepository : MongoDbCollectionBase, IVacancyRepository
{
private const string Database = "recruit";
private const string Collection = "vacancies";

private const string EmployerAccountId = "employerAccountId";

public MongoDbVacancyRepository(ILogger<MongoDbVacancyRepository> logger, IOptions<MongoDbConnectionDetails> details)
Expand Down Expand Up @@ -81,15 +81,13 @@ public async Task<Vacancy> GetSingleVacancyForPostcode(string postcode)
builder.Ne(v => v.EmployerLocation.Latitude, null) &
builder.Ne(v => v.EmployerLocation.Longitude, null);

var options = new FindOptions<Vacancy>
{
Sort = Builders<Vacancy>.Sort.Descending(v => v.VacancyReference),
Limit = 1
};

var collection = GetCollection<Vacancy>();
var result = await RetryPolicy.ExecuteAsync(context => collection.FindAsync(filter, options), new Context(nameof(GetSingleVacancyForPostcode)));
return result.SingleOrDefault();
var result = await RetryPolicy.ExecuteAsync(context => collection.FindAsync(filter), new Context(nameof(GetSingleVacancyForPostcode)));

return result
.ToList()
.OrderByDescending(x => x.VacancyReference)
.SingleOrDefault();
}

public async Task UpdateAsync(Vacancy vacancy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ public async Task<IEnumerable<VacancyReview>> GetAllAsync()
var collection = GetCollection<VacancyReview>();
var result = await RetryPolicy.ExecuteAsync(context => collection
.Find(FilterDefinition<VacancyReview>.Empty)
.Sort(Builders<VacancyReview>.Sort.Descending(r => r.CreatedDate))
.ToListAsync(), new Context(nameof(GetAllAsync)));

return result;
return result.OrderByDescending(x => x.CreatedDate);
}

public Task UpdateAsync(VacancyReview review)
Expand Down

0 comments on commit fda74e9

Please sign in to comment.