@@ -47,20 +47,23 @@ public void Update(JObject entity)
47
47
Term term = resolver . Resolver . Identity ( entity ) ;
48
48
LuceneDocumentEntry doc = mapper . Create ( entity ) ;
49
49
Writer . UpdateDocument ( term , doc . Document ) ;
50
+ throttledCommit . Increment ( ) ;
50
51
DebugInfo ( $ "Writer.UpdateDocument({ term } , <doc>)") ;
51
52
}
52
53
53
54
public void Create ( JObject entity )
54
55
{
55
56
LuceneDocumentEntry doc = mapper . Create ( entity ) ;
56
57
Writer . AddDocument ( doc . Document ) ;
58
+ throttledCommit . Increment ( ) ;
57
59
DebugInfo ( $ "Writer.AddDocument(<doc>)") ;
58
60
}
59
61
60
62
public void Delete ( JObject entity )
61
63
{
62
64
Term term = resolver . Resolver . Identity ( entity ) ;
63
65
Writer . DeleteDocuments ( term ) ;
66
+ throttledCommit . Increment ( ) ;
64
67
DebugInfo ( $ "Writer.UpdateDocuments({ term } )") ;
65
68
}
66
69
@@ -92,10 +95,11 @@ public class ThrottledCommit
92
95
private readonly JsonIndexWriter target ;
93
96
private readonly WaitHandle handle = new AutoResetEvent ( false ) ;
94
97
private readonly long upperBound = Stopwatch . Frequency * 10 ;
95
- private readonly long lowerBound = Stopwatch . Frequency / 10 ;
98
+ private readonly long lowerBound = Stopwatch . Frequency / 5 ;
96
99
97
100
private long lastInvocation = 0 ;
98
101
private long lastRequest = 0 ;
102
+ private long writes = 0 ;
99
103
100
104
public ThrottledCommit ( JsonIndexWriter target )
101
105
{
@@ -122,6 +126,9 @@ private void Tick()
122
126
123
127
private void Commit ( )
124
128
{
129
+ if ( Interlocked . Exchange ( ref writes , 0 ) < 1 )
130
+ return ;
131
+
125
132
try
126
133
{
127
134
target . Writer . Commit ( ) ;
@@ -136,7 +143,11 @@ private void Commit()
136
143
public void Invoke ( )
137
144
{
138
145
lastRequest = Stopwatch . GetTimestamp ( ) ;
139
- Tick ( ) ;
146
+ }
147
+
148
+ public void Increment ( )
149
+ {
150
+ Interlocked . Increment ( ref writes ) ;
140
151
}
141
152
}
142
153
}
0 commit comments