@@ -44,6 +44,10 @@ func (db *BigtableDB) FlushCache(ctx context.Context, logger *zap.Logger, cache
44
44
observationMuts := make ([]* bigtable.Mutation , 0 )
45
45
observationRows := make ([]string , 0 )
46
46
47
+ // Prepare bulk mutations for message indexes
48
+ indexMuts := make ([]* bigtable.Mutation , 0 , len (cache .Messages ))
49
+ indexRows := make ([]string , 0 , len (cache .Messages ))
50
+
47
51
for messageID , message := range cache .Messages {
48
52
// Prepare message mutation
49
53
messageMut , err := createMessageMutation (message )
@@ -64,20 +68,39 @@ func (db *BigtableDB) FlushCache(ctx context.Context, logger *zap.Logger, cache
64
68
observationMuts = append (observationMuts , observationMut )
65
69
observationRows = append (observationRows , observationRow )
66
70
}
71
+
72
+ // Prepare message index mutation
73
+ indexMut := bigtable .NewMutation ()
74
+ indexMut .Set ("indexData" , "placeholder" , bigtable .Now (), nil )
75
+ indexMuts = append (indexMuts , indexMut )
76
+ indexRows = append (indexRows , string (messageID ))
67
77
}
68
78
79
+ // Apply bulk mutations for messages
69
80
err := db .ApplyBulk (ctx , MessageTableName , messageRows , messageMuts )
70
81
if err != nil {
71
82
logger .Error ("Failed to apply bulk mutations for messages" , zap .Error (err ))
72
83
return err
73
84
}
74
85
86
+ // Apply bulk mutations for observations
75
87
err = db .ApplyBulk (ctx , ObservationTableName , observationRows , observationMuts )
76
88
if err != nil {
77
89
logger .Error ("Failed to apply bulk mutations for observations" , zap .Error (err ))
78
90
return err
79
91
}
80
92
93
+ // Apply bulk mutations for message indexes
94
+ err = db .ApplyBulk (ctx , MessageIndexTableName , indexRows , indexMuts )
95
+ if err != nil {
96
+ logger .Error ("Failed to apply bulk mutations for message indexes" , zap .Error (err ))
97
+ return err
98
+ }
99
+
100
+ logger .Info ("Successfully applied bulk mutations for messages" , zap .Int ("count" , len (messageMuts )))
101
+ logger .Info ("Successfully applied bulk mutations for observations" , zap .Int ("count" , len (observationMuts )))
102
+ logger .Info ("Successfully applied bulk mutations for message indexes" , zap .Int ("count" , len (indexMuts )))
103
+
81
104
return nil
82
105
}
83
106
0 commit comments