From d2dcb4598ded29c763325790ccc1a587529f5c88 Mon Sep 17 00:00:00 2001 From: Jonathan Poltak Samosir Date: Fri, 9 Mar 2018 11:40:04 +0700 Subject: [PATCH] Encapsulate page model `loadRels` in index methods - prev `getPage` was returning a Page model, but Page model is specific to the Dexie implementation - hide this away, do the `loadRels` in the new index `getPage` method (old index implementation can completely ignore) --- src/activity-logger/background/log-page-visit.js | 2 -- src/search/background/index.js | 2 -- src/search/index.test.js | 3 --- src/search/search-index-new/util.js | 11 ++++++++++- src/search/search-index-old/api.js | 1 - 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/activity-logger/background/log-page-visit.js b/src/activity-logger/background/log-page-visit.js index 3328be5064..5e39ff60db 100644 --- a/src/activity-logger/background/log-page-visit.js +++ b/src/activity-logger/background/log-page-visit.js @@ -20,8 +20,6 @@ export async function logInitPageVisit(tabId, secsSinceLastIndex = 20) { const existingPage = await index.getPage(tab.url) if (existingPage != null) { - await existingPage.loadRels() - // Store just new visit if existing page has been indexed recently (`secsSinceLastIndex`) // also clear scheduled content indexing if ( diff --git a/src/search/background/index.js b/src/search/background/index.js index e2599cacea..fe3c99c95d 100644 --- a/src/search/background/index.js +++ b/src/search/background/index.js @@ -32,8 +32,6 @@ async function transformPageForSending(page) { return null } - await page.loadRels() - return { hasBookmark: page.hasBookmark, tags: page.tags, diff --git a/src/search/index.test.js b/src/search/index.test.js index 9f584734a2..602e2c4e8d 100644 --- a/src/search/index.test.js +++ b/src/search/index.test.js @@ -92,8 +92,6 @@ const runSuite = useOld => () => { describe('read ops', () => { test('fetch page by URL', async () => { const runChecks = async page => { - await page.loadRels() - expect(page).toBeDefined() expect(page).not.toBeNull() expect(page.hasBookmark).toBe(false) @@ -106,7 +104,6 @@ const runSuite = useOld => () => { runChecks(await index.getPage('test.com/test')) // Should get normalized the same const page = await index.getPage(TEST_PAGE_2.url) - await page.loadRels() expect(page).toBeDefined() expect(page).not.toBeNull() diff --git a/src/search/search-index-new/util.js b/src/search/search-index-new/util.js index 1b922641a7..e5f5cdd356 100644 --- a/src/search/search-index-new/util.js +++ b/src/search/search-index-new/util.js @@ -1,7 +1,16 @@ import db from '.' import normalizeUrl from 'src/util/encode-url-for-id' -export const getPage = url => db.pages.get(normalizeUrl(url)) +export async function getPage(url) { + const page = await db.pages.get(normalizeUrl(url)) + + if (page != null) { + // Force-load any related records from other tables + await page.loadRels() + } + + return page +} /** * Hardcoded replacement for now. diff --git a/src/search/search-index-old/api.js b/src/search/search-index-old/api.js index 729dd7b60a..580f0124c1 100644 --- a/src/search/search-index-old/api.js +++ b/src/search/search-index-old/api.js @@ -104,7 +104,6 @@ export async function getPage(url) { return page != null ? { - loadRels: () => Promise.resolve(), latest: +page.latest, hasBookmark: page.bookmarks.size > 0, tags: page.tags ? [...page.tags].map(removeKeyType) : [],