Skip to content

Commit 2e646ae

Browse files
committed
fix: elastic search update
1 parent fb9ccac commit 2e646ae

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

packages/velog-server/src/services/PostApiService/index.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class PostApiService implements Service {
5151
private readonly turnstileService: TurnstileService,
5252
) {}
5353
public async write(input: WritePostInput, signedUserId?: string, ip = ''): Promise<Post> {
54-
const { data, post, userId, series_id } = await this.initializePostProcess<'write'>({
54+
const { data, post, series_id } = await this.initializePostProcess<'write'>({
5555
input,
5656
signedUserId,
5757
type: 'write',
@@ -62,14 +62,8 @@ export class PostApiService implements Service {
6262
await this.seriesService.appendToSeries(series_id, post.id)
6363
}
6464

65-
try {
66-
await Promise.all([
67-
data.is_temp ? null : this.searchService.searchSync.update(post.id),
68-
this.graphcdn.purgeRecentPosts(),
69-
this.graphcdn.purgeUser(userId),
70-
])
71-
} catch (error) {
72-
console.log(error)
65+
if (!data.is_temp) {
66+
await this.searchService.searchSync.update(post.id)
7367
}
7468

7569
return post
@@ -110,6 +104,13 @@ export class PostApiService implements Service {
110104
])
111105
}
112106

107+
await this.db.post.update({
108+
where: {
109+
id: post.id,
110+
},
111+
data,
112+
})
113+
113114
try {
114115
await Promise.all([
115116
data.is_temp ? null : this.searchService.searchSync.update(post.id),
@@ -131,13 +132,6 @@ export class PostApiService implements Service {
131132
})
132133
}
133134

134-
await this.db.post.update({
135-
where: {
136-
id: post.id,
137-
},
138-
data,
139-
})
140-
141135
return { ...post, url_slug: data.url_slug }
142136
}
143137
private async initializePostProcess<T extends 'write' | 'edit'>({

packages/velog-server/src/services/SearchService/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ export class SearchService implements Service {
5454
const serialized = this.serializePost(postWithTags)
5555

5656
try {
57-
return this.elasticSearch.client.index({
57+
const result = await this.elasticSearch.client.index({
5858
id: postId,
5959
index: 'posts',
6060
body: serialized,
6161
})
62+
63+
return result
6264
} catch (error) {
6365
console.log('elasticsearch post update', error)
6466
throw error

0 commit comments

Comments
 (0)