Merge pull request #235 from omnivore-app/fix/reading-progress-lookup

Dont make queries for readingProgressPercent unless we have to
This commit is contained in:
Jackson Harper 2022-03-15 09:26:03 -07:00 committed by GitHub
commit 388bbde064
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -383,8 +383,30 @@ export const functionResolvers = {
? ContentReader.Pdf
: ContentReader.Web
},
readingProgressPercent: getReadingProgressForArticleResolver,
readingProgressAnchorIndex: getReadingProgressAnchorIndexForArticleResolver,
async readingProgressPercent(
article: { id: string; articleReadingProgress?: number },
_: unknown,
ctx: WithDataSourcesContext & { claims: Claims }
) {
if ('articleReadingProgress' in article) {
return article.articleReadingProgress
}
return (
await ctx.models.userArticle.getByArticleId(ctx.claims.uid, article.id)
)?.articleReadingProgress
},
async readingProgressAnchorIndex(
article: { id: string; articleReadingProgressAnchorIndex?: number },
_: unknown,
ctx: WithDataSourcesContext & { claims: Claims }
) {
if ('articleReadingProgressAnchorIndex' in article) {
return article.articleReadingProgressAnchorIndex
}
return (
await ctx.models.userArticle.getByArticleId(ctx.claims.uid, article.id)
)?.articleReadingProgressAnchorIndex
},
async highlights(
article: { id: string; userId?: string },
_: { input: ArticleHighlightsInput },