Skip to content

Commit 92cdeb1

Browse files
committed
Fixed post parsing bug & improved effiency by breaking loop if post already exists.
1 parent 34e1fb6 commit 92cdeb1

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/lib/reddit.ts

100644100755
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import axios from 'axios'
44
import Snoowrap from 'snoowrap'
5-
import { PrismaClient } from '@prisma/client'
65
import { CommentStream } from 'snoostorm'
76
import { sendNotification } from './notifications'
87
import prisma from '@/lib/db'
@@ -203,7 +202,7 @@ export async function storePosts(posts: Array<any>) {
203202
for (const post of posts) {
204203
try {
205204
// Check for existing record
206-
const existing = await prisma.post.findUnique({
205+
const existing = await prisma.redditPost.findUnique({
207206
where: { url: post.url },
208207
})
209208

@@ -212,7 +211,7 @@ export async function storePosts(posts: Array<any>) {
212211
continue
213212
}
214213

215-
const createdPost = await prisma.post.create({ data: post })
214+
const createdPost = await prisma.redditPost.create({ data: post })
216215

217216
// Build notification payload
218217
const notificationPayload = {

0 commit comments

Comments
 (0)