Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bookmark and view of bookmark #1232

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

paahaad
Copy link
Contributor

@paahaad paahaad commented Sep 15, 2024

PR Fixes:

  • 1 Added support for folder and notion doc
  • 2 fix the bookmark state in the course view page. which was causing the bookmark button be active thus allowing the user to create same bookmark again polluting the db.

Resolves #1231
Screencast from 15-09-24 09:52:22 PM IST.webm

Checklist before requesting a review

  • I have performed a self-review of my code
  • I assure there is no similar/duplicate pull request regarding same issue

@hkirat
Copy link
Contributor

hkirat commented Sep 15, 2024

@devsargam

contentId={contentId}
/>
);
} else if (type === 'folder' && !parent) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this else sir? from what i can see you are returning the same thing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

videoUrl is diff in both the case. there was already an implementation for type == 'video'. I do not want to break that. plus control will not go inside if in case of folder because parent will be null.

@paahaad
Copy link
Contributor Author

paahaad commented Sep 18, 2024

@siinghd let me know if you feel some changes is required.

also, rn in production user can create same bookmark multiple time. creating multiple entry of same contentId. I think we should change the schema of bookmark to

model Bookmark {
  id        Int      @id @default(autoincrement())
  userId    String
  contentId Int
  user      User     @relation(fields: [userId], references: [id], onDelete: Cascade)
  content   Content  @relation(fields: [contentId], references: [id])
  createdAt DateTime @default(now())

  @@unique([userId, contentId])
} 

here is a script to delete multiple records then we can do prisma migrate.

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

async function deduplicateBookmarks() {
  console.log('Starting deduplication process...')

  const allBookmarks = await prisma.bookmark.findMany({
    select: {
      id: true,
      userId: true,
      contentId: true,
    },
    orderBy: {
      createdAt: 'asc',
    },
  })

  console.log(`Total bookmarks found: ${allBookmarks.length}`)

  const uniqueCombinations = new Set()
  const duplicateIds = []

  for (const bookmark of allBookmarks) {
    const key = `${bookmark.userId}-${bookmark.contentId}`
    if (uniqueCombinations.has(key)) {
      duplicateIds.push(bookmark.id)
    } else {
      uniqueCombinations.add(key)
    }
  }

  console.log(`Duplicate bookmarks found: ${duplicateIds.length}`)

  if (duplicateIds.length > 0) {
    const deleteResult = await prisma.bookmark.deleteMany({
      where: {
        id: {
          in: duplicateIds,
        },
      },
    })

    console.log(`Deleted ${deleteResult.count} duplicate bookmarks`)
  } else {
    console.log('No duplicates found')
  }

  console.log('Deduplication process completed')
}

deduplicateBookmarks()
  

@devsargam devsargam self-assigned this Sep 20, 2024
@devsargam devsargam self-requested a review September 20, 2024 12:20
@devsargam devsargam merged commit 59a4586 into code100x:main Oct 4, 2024
1 check failed
@devsargam
Copy link
Collaborator

thankss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: Bookmark is broken.
4 participants