batching upload_files
This commit is contained in:
@ -38,6 +38,7 @@ import {
|
||||
countDailyServiceUsage,
|
||||
createServiceUsage,
|
||||
} from './services/service_usage'
|
||||
import { batchGetUploadFilesByIds } from './services/upload_file'
|
||||
import { tracer } from './tracing'
|
||||
import { getClaimsByToken, setAuthInCookie } from './utils/auth'
|
||||
import { SetClaimsRole } from './utils/dictionary'
|
||||
@ -110,6 +111,7 @@ const contextFunc: ContextFunction<ExpressContext, ResolverContext> = async ({
|
||||
recommendations: new DataLoader(
|
||||
batchGetRecommendationsFromLibraryItemIds
|
||||
),
|
||||
uploadFiles: new DataLoader(batchGetUploadFilesByIds),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -25,7 +25,6 @@ import {
|
||||
} from '../generated/graphql'
|
||||
import { getAISummary } from '../services/ai-summaries'
|
||||
import { findUserFeatures } from '../services/features'
|
||||
import { findUploadFileById } from '../services/upload_file'
|
||||
import {
|
||||
highlightDataToHighlight,
|
||||
isBase64Image,
|
||||
@ -407,7 +406,9 @@ export const functionResolvers = {
|
||||
ctx.claims &&
|
||||
article.uploadFileId
|
||||
) {
|
||||
const upload = await findUploadFileById(article.uploadFileId)
|
||||
const upload = await ctx.dataLoaders.uploadFiles.load(
|
||||
article.uploadFileId
|
||||
)
|
||||
if (!upload || !upload.fileName) {
|
||||
return undefined
|
||||
}
|
||||
@ -481,7 +482,7 @@ export const functionResolvers = {
|
||||
ctx.claims &&
|
||||
item.uploadFileId
|
||||
) {
|
||||
const upload = await findUploadFileById(item.uploadFileId)
|
||||
const upload = await ctx.dataLoaders.uploadFiles.load(item.uploadFileId)
|
||||
if (!upload || !upload.fileName) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import { ReadingProgressDataSource } from '../datasources/reading_progress_data_
|
||||
import { Highlight } from '../entity/highlight'
|
||||
import { Label } from '../entity/label'
|
||||
import { Recommendation } from '../entity/recommendation'
|
||||
import { UploadFile } from '../entity/upload_file'
|
||||
import { PubsubClient } from '../pubsub'
|
||||
|
||||
export interface Claims {
|
||||
@ -49,6 +50,7 @@ export interface RequestContext {
|
||||
labels: DataLoader<string, Label[]>
|
||||
highlights: DataLoader<string, Highlight[]>
|
||||
recommendations: DataLoader<string, Recommendation[]>
|
||||
uploadFiles: DataLoader<string, UploadFile | undefined>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import normalizeUrl from 'normalize-url'
|
||||
import path from 'path'
|
||||
import { In } from 'typeorm'
|
||||
import { v4 as uuid } from 'uuid'
|
||||
import { LibraryItemState } from '../entity/library_item'
|
||||
import { UploadFile } from '../entity/upload_file'
|
||||
import {
|
||||
@ -18,7 +20,16 @@ import {
|
||||
} from '../utils/uploads'
|
||||
import { validateUrl } from './create_page_save_request'
|
||||
import { createOrUpdateLibraryItem } from './library_item'
|
||||
import { v4 as uuid } from 'uuid'
|
||||
|
||||
export const batchGetUploadFilesByIds = async (
|
||||
ids: readonly string[]
|
||||
): Promise<(UploadFile | undefined)[]> => {
|
||||
const uploadFiles = await getRepository(UploadFile).findBy({
|
||||
id: In(ids as string[]),
|
||||
})
|
||||
|
||||
return ids.map((id) => uploadFiles.find((uploadFile) => uploadFile.id === id))
|
||||
}
|
||||
|
||||
const isFileUrl = (url: string): boolean => {
|
||||
const parsedUrl = new URL(url)
|
||||
|
||||
Reference in New Issue
Block a user