Skip to content
This repository
Browse code

Update LuceneIndexingService to use Ninject EF DbContext for any give…

…n creation or deletion of a package on the feed. WebBackgrounder task will use default constructor that news up a DbContext.
  • Loading branch information...
commit 40e0762ff8605072b0d82acafdd94aeb756febe6 1 parent 41a8ab0
Steve Chapman chappoo authored pranavkm committed

Showing 1 changed file with 14 additions and 8 deletions. Show diff stats Hide diff stats

  1. +14 8 Website/Infrastructure/Lucene/LuceneIndexingService.cs
22 Website/Infrastructure/Lucene/LuceneIndexingService.cs
@@ -9,16 +9,28 @@
9 9 using Lucene.Net.Analysis.Standard;
10 10 using Lucene.Net.Documents;
11 11 using Lucene.Net.Index;
  12 +using Ninject;
12 13
13 14 namespace NuGetGallery
14 15 {
15 16 public class LuceneIndexingService : IIndexingService
16 17 {
  18 + private readonly DbContext _entitiesContext;
17 19 private static readonly object indexWriterLock = new object();
18 20 private static readonly TimeSpan indexRecreateInterval = TimeSpan.FromDays(3);
19 21 private static readonly char[] idSeparators = new[] { '.', '-' };
20 22 private static IndexWriter indexWriter;
21 23
  24 + public LuceneIndexingService() : this(new EntitiesContext())
  25 + {
  26 + }
  27 +
  28 + [Inject]
  29 + public LuceneIndexingService(IEntitiesContext entitiesContext)
  30 + {
  31 + _entitiesContext = (DbContext)entitiesContext;
  32 + }
  33 +
22 34 public void UpdateIndex()
23 35 {
24 36 DateTime? lastWriteTime = GetLastWriteTime();
@@ -37,10 +49,9 @@ public void UpdateIndex()
37 49 // Set the index create time to now. This would tell us when we last rebuilt the index.
38 50 UpdateIndexRefreshTime();
39 51 }
40   -
41   - using (var context = CreateContext())
  52 + if (_entitiesContext != null)
42 53 {
43   - var packages = GetPackages(context, lastWriteTime);
  54 + var packages = GetPackages(_entitiesContext, lastWriteTime);
44 55 if (packages.Count > 0)
45 56 {
46 57 AddPackages(packages);
@@ -49,11 +60,6 @@ public void UpdateIndex()
49 60 UpdateLastWriteTime();
50 61 }
51 62
52   - protected internal virtual DbContext CreateContext()
53   - {
54   - return new EntitiesContext();
55   - }
56   -
57 63 protected internal virtual List<PackageIndexEntity> GetPackages(DbContext context, DateTime? lastIndexTime)
58 64 {
59 65 string sql = @"SELECT p.[Key], pr.Id, p.Title, p.Description, p.Tags, p.FlattenedAuthors as Authors, pr.DownloadCount,

0 comments on commit 40e0762

Please sign in to comment.
Something went wrong with that request. Please try again.