Skip to content

Commit 5903166

Browse files
committed
chore: fix the algolia sync
1 parent 9d156c6 commit 5903166

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/collections/CommunityHelp/updateAlgolia.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const updateAlgolia = async (id: string, helpful: boolean): Promise<void>
1717
objectID: id,
1818
},
1919
{
20-
createIfNotExists: true,
20+
createIfNotExists: false,
2121
},
2222
)
2323
.then(() => {

src/scripts/syncToAlgolia.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import algoliasearch from 'algoliasearch'
2-
import payload from 'payload'
32

4-
const appID = process.env.NEXT_PUBLIC_ALGOLIA_CH_ID || ''
5-
const apiKey = process.env.NEXT_PRIVATE_ALGOLIA_API_KEY || ''
6-
const indexName = process.env.NEXT_PUBLIC_ALGOLIA_CH_INDEX_NAME || ''
3+
const {
4+
NEXT_PRIVATE_ALGOLIA_API_KEY,
5+
NEXT_PUBLIC_ALGOLIA_CH_ID,
6+
NEXT_PUBLIC_ALGOLIA_CH_INDEX_NAME,
7+
NEXT_PUBLIC_CMS_URL,
8+
} = process.env
9+
10+
const appID = NEXT_PUBLIC_ALGOLIA_CH_ID || ''
11+
const apiKey = NEXT_PRIVATE_ALGOLIA_API_KEY || ''
12+
const indexName = NEXT_PUBLIC_ALGOLIA_CH_INDEX_NAME || ''
713

814
const client = algoliasearch(appID, apiKey)
915

@@ -39,16 +45,17 @@ export const syncToAlgolia = async (): Promise<void> => {
3945
throw new Error('Algolia environment variables are not set')
4046
}
4147

42-
const { docs } = await payload.find({
43-
collection: 'community-help',
44-
limit: 30000,
45-
})
48+
const communityHelpThreads = await fetch(
49+
`${NEXT_PUBLIC_CMS_URL}/api/community-help?limit=0`,
50+
).then((res) => res.json())
51+
52+
const docs = communityHelpThreads?.docs
4653

4754
const discordDocs: DiscordDoc[] = []
4855
const githubDocs: GithubDoc[] = []
4956

5057
docs.forEach((doc) => {
51-
const { communityHelpJSON, discordID, githubID, helpful } = doc as any
58+
const { communityHelpJSON, discordID, githubID, helpful } = doc
5259

5360
if (discordID) {
5461
const { slug, info, intro, messageCount, messages } = communityHelpJSON
@@ -60,9 +67,11 @@ export const syncToAlgolia = async (): Promise<void> => {
6067
helpful: helpful ?? false,
6168
messageCount,
6269
messages: messages.map((message) => {
63-
return {
64-
author: message.authorName,
65-
content: message.content,
70+
if (message) {
71+
return {
72+
author: message.authorName,
73+
content: message.content,
74+
}
6675
}
6776
}),
6877
objectID: info.id,

0 commit comments

Comments
 (0)