fix: find library item by url not using correct index
This commit is contained in:
@ -38,7 +38,6 @@ export enum DirectionalityType {
|
||||
RTL = 'RTL',
|
||||
}
|
||||
|
||||
@Unique('library_item_user_original_url', ['user', 'originalUrl'])
|
||||
@Entity({ name: 'library_item' })
|
||||
export class LibraryItem {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
|
||||
@ -8,10 +8,12 @@ export const libraryItemRepository = appDataSource
|
||||
return this.findOneBy({ id })
|
||||
},
|
||||
|
||||
findByUrl(url: string) {
|
||||
return this.findOneBy({
|
||||
originalUrl: url,
|
||||
})
|
||||
findByUserIdAndUrl(userId: string, url: string) {
|
||||
// md5 is used to hash the url to avoid the length limit of the index
|
||||
return this.createQueryBuilder()
|
||||
.where('user_id = :userId', { userId })
|
||||
.andWhere('md5(original_url) = md5(:url)', { url })
|
||||
.getOne()
|
||||
},
|
||||
|
||||
countByCreatedAt(createdAt: Date) {
|
||||
|
||||
@ -13,6 +13,7 @@ import {
|
||||
SaveResult,
|
||||
} from '../generated/graphql'
|
||||
import { authTrx } from '../repository'
|
||||
import { libraryItemRepository } from '../repository/library_item'
|
||||
import { enqueueThumbnailJob } from '../utils/createTask'
|
||||
import {
|
||||
cleanUrl,
|
||||
@ -119,10 +120,9 @@ export const savePage = async (
|
||||
} else {
|
||||
// check if the item already exists
|
||||
const existingLibraryItem = await authTrx((t) =>
|
||||
t.getRepository(LibraryItem).findOneBy({
|
||||
user: { id: user.id },
|
||||
originalUrl: itemToSave.originalUrl,
|
||||
})
|
||||
t
|
||||
.withRepository(libraryItemRepository)
|
||||
.findByUserIdAndUrl(input.url, user.id)
|
||||
)
|
||||
if (existingLibraryItem) {
|
||||
clientRequestId = existingLibraryItem.id
|
||||
|
||||
Reference in New Issue
Block a user