Merge pull request #3490 from omnivore-app/fix/index

fix: find library item by url not using correct index
This commit is contained in:
Hongbo Wu
2024-02-02 17:07:06 +08:00
committed by GitHub
3 changed files with 10 additions and 9 deletions

View File

@ -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')

View File

@ -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) {

View File

@ -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(user.id, input.url)
)
if (existingLibraryItem) {
clientRequestId = existingLibraryItem.id