@@ -2,6 +2,7 @@ package service
2
2
3
3
import (
4
4
"context"
5
+ "time"
5
6
6
7
"github.com/bytedance/sonic"
7
8
"github.com/krau/ManyACG/adapter"
@@ -99,7 +100,9 @@ func (m *artworkSyncManager) ProcessArtworkUpdateEvent(event bson.M) {
99
100
common .Logger .Errorf ("decode artwork from event error: %s" , err )
100
101
return
101
102
}
102
- searchDoc , err := adapter .ConvertToSearchDoc (context .Background (), artwork )
103
+ ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
104
+ defer cancel ()
105
+ searchDoc , err := adapter .ConvertToSearchDoc (ctx , artwork )
103
106
if err != nil {
104
107
common .Logger .Errorf ("convert to search doc error: %s" , err )
105
108
return
@@ -109,7 +112,7 @@ func (m *artworkSyncManager) ProcessArtworkUpdateEvent(event bson.M) {
109
112
common .Logger .Errorf ("marshal search doc error: %s" , err )
110
113
return
111
114
}
112
- task , err := common .MeilisearchClient .Index (config .Cfg .Search .MeiliSearch .Index ).UpdateDocuments ( artworkJSON )
115
+ task , err := common .MeilisearchClient .Index (config .Cfg .Search .MeiliSearch .Index ).UpdateDocumentsWithContext ( ctx , artworkJSON )
113
116
if err != nil {
114
117
common .Logger .Errorf ("update artwork to meilisearch error: %s" , err )
115
118
return
@@ -119,7 +122,9 @@ func (m *artworkSyncManager) ProcessArtworkUpdateEvent(event bson.M) {
119
122
120
123
func (m * artworkSyncManager ) ProcessArtworkDeleteEvent (event bson.M ) {
121
124
docID := event ["documentKey" ].(bson.M )["_id" ].(primitive.ObjectID ).Hex ()
122
- task , err := common .MeilisearchClient .Index (config .Cfg .Search .MeiliSearch .Index ).DeleteDocument (docID )
125
+ ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
126
+ defer cancel ()
127
+ task , err := common .MeilisearchClient .Index (config .Cfg .Search .MeiliSearch .Index ).DeleteDocumentWithContext (ctx , docID )
123
128
if err != nil {
124
129
common .Logger .Errorf ("delete artwork from meilisearch error: %s" , err )
125
130
return
@@ -134,7 +139,9 @@ func (m *artworkSyncManager) ProcessArtworkReplaceEvent(event bson.M) {
134
139
common .Logger .Errorf ("decode artwork from event error: %s" , err )
135
140
return
136
141
}
137
- searchDoc , err := adapter .ConvertToSearchDoc (context .Background (), artwork )
142
+ ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
143
+ defer cancel ()
144
+ searchDoc , err := adapter .ConvertToSearchDoc (ctx , artwork )
138
145
if err != nil {
139
146
common .Logger .Errorf ("convert to search doc error: %s" , err )
140
147
return
@@ -144,7 +151,7 @@ func (m *artworkSyncManager) ProcessArtworkReplaceEvent(event bson.M) {
144
151
common .Logger .Errorf ("marshal search doc error: %s" , err )
145
152
return
146
153
}
147
- task , err := common .MeilisearchClient .Index (config .Cfg .Search .MeiliSearch .Index ).UpdateDocuments ( artworkJSON )
154
+ task , err := common .MeilisearchClient .Index (config .Cfg .Search .MeiliSearch .Index ).UpdateDocumentsWithContext ( ctx , artworkJSON )
148
155
if err != nil {
149
156
common .Logger .Errorf ("update artwork to meilisearch error: %s" , err )
150
157
return
0 commit comments