@@ -63,14 +63,11 @@ func (i *ContactIndexer) Index(db *sql.DB, rebuild, cleanup bool) (string, error
63
63
i .log ().Debug ("indexing newer than last modified" , "index" , physicalIndex , "last_modified" , lastModified )
64
64
65
65
// now index our docs
66
- start := time .Now ()
67
- created , updated , deleted , err := i .indexModified (ctx , db , physicalIndex , lastModified .Add (- 5 * time .Second ), rebuild )
66
+ err = i .indexModified (ctx , db , physicalIndex , lastModified .Add (- 5 * time .Second ), rebuild )
68
67
if err != nil {
69
68
return "" , fmt .Errorf ("error indexing documents: %w" , err )
70
69
}
71
70
72
- i .recordComplete (created + updated , deleted , time .Since (start ))
73
-
74
71
// if the index didn't previously exist or we are rebuilding, remap to our alias
75
72
if remapAlias {
76
73
err := i .updateAlias (physicalIndex )
@@ -153,7 +150,7 @@ SELECT org_id, id, modified_on, is_active, row_to_json(t) FROM (
153
150
`
154
151
155
152
// IndexModified queries and indexes all contacts with a lastModified greater than or equal to the passed in time
156
- func (i * ContactIndexer ) indexModified (ctx context.Context , db * sql.DB , index string , lastModified time.Time , rebuild bool ) ( int , int , int , error ) {
153
+ func (i * ContactIndexer ) indexModified (ctx context.Context , db * sql.DB , index string , lastModified time.Time , rebuild bool ) error {
157
154
totalFetched , totalCreated , totalUpdated , totalDeleted := 0 , 0 , 0 , 0
158
155
159
156
var modifiedOn time.Time
@@ -193,17 +190,17 @@ func (i *ContactIndexer) indexModified(ctx context.Context, db *sql.DB, index st
193
190
194
191
// no more rows? return
195
192
if err == sql .ErrNoRows {
196
- return 0 , 0 , 0 , nil
193
+ return nil
197
194
}
198
195
if err != nil {
199
- return 0 , 0 , 0 , err
196
+ return err
200
197
}
201
198
defer rows .Close ()
202
199
203
200
for rows .Next () {
204
201
err = rows .Scan (& orgID , & id , & modifiedOn , & isActive , & contactJSON )
205
202
if err != nil {
206
- return 0 , 0 , 0 , err
203
+ return err
207
204
}
208
205
209
206
batchFetched ++
@@ -226,14 +223,14 @@ func (i *ContactIndexer) indexModified(ctx context.Context, db *sql.DB, index st
226
223
// write to elastic search in batches
227
224
if batchFetched % i .batchSize == 0 {
228
225
if err := indexSubBatch (subBatch ); err != nil {
229
- return 0 , 0 , 0 , err
226
+ return err
230
227
}
231
228
}
232
229
}
233
230
234
231
if subBatch .Len () > 0 {
235
232
if err := indexSubBatch (subBatch ); err != nil {
236
- return 0 , 0 , 0 , err
233
+ return err
237
234
}
238
235
}
239
236
@@ -268,13 +265,15 @@ func (i *ContactIndexer) indexModified(ctx context.Context, db *sql.DB, index st
268
265
log .Debug ("indexed contact batch" )
269
266
}
270
267
268
+ i .recordActivity (batchCreated + batchUpdated , batchDeleted , time .Since (batchStart ))
269
+
271
270
// last modified stayed the same and we didn't add anything, seen it all, break out
272
271
if lastModified .Equal (queryModified ) && batchCreated == 0 {
273
272
break
274
273
}
275
274
}
276
275
277
- return totalCreated , totalUpdated , totalDeleted , nil
276
+ return nil
278
277
}
279
278
280
279
func (i * ContactIndexer ) GetDBLastModified (ctx context.Context , db * sql.DB ) (time.Time , error ) {
0 commit comments