diff --git a/packages/api/src/datalayer/links/index.ts b/packages/api/src/datalayer/links/index.ts index 4d52e47a2..10a8d991e 100644 --- a/packages/api/src/datalayer/links/index.ts +++ b/packages/api/src/datalayer/links/index.ts @@ -51,15 +51,16 @@ const LINK_COLS = [ 'omnivore.pages.title', 'omnivore.pages.description', 'omnivore.pages.hash', - 'omnivore.pages.originalHtml', - 'omnivore.pages.content', 'omnivore.pages.author', 'omnivore.pages.image', 'omnivore.pages.pageType', 'omnivore.pages.publishedAt', ] -const linkCols = (tx: Knex) => { +// When fetching the library list we don't need to +// pull all the content out of the database into +// memory just to discard it later +const linkColsWithoutContent = (tx: Knex) => { return [ tx.raw(` CASE @@ -79,6 +80,14 @@ const linkCols = (tx: Knex) => { ] } +const linkCols = (tx: Knex) => { + return [ + 'omnivore.pages.content', + 'omnivore.pages.originalHtml', + ...linkColsWithoutContent(tx), + ] +} + const readFilterQuery = (filter: ReadFilter) => { switch (filter) { case ReadFilter.ALL: @@ -405,7 +414,7 @@ class UserArticleModel extends DataModel< const whereOperator = sort?.order === SortOrder.Ascending ? '>=' : '<=' const queryPromise = tx(this.tableName) - .select(linkCols(tx)) + .select(linkColsWithoutContent(tx)) .innerJoin(Table.PAGES, 'pages.id', 'links.article_id') .where({ 'links.user_id': userId }) .where(tx.raw(readFilterQuery(readFilter)))