Skip to content

Commit

Permalink
Encapsulate page model loadRels in index methods
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
poltak committed Mar 9, 2018
1 parent 633f46c commit d2dcb45
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
2 changes: 0 additions & 2 deletions src/activity-logger/background/log-page-visit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 0 additions & 2 deletions src/search/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ async function transformPageForSending(page) {
return null
}

await page.loadRels()

return {
hasBookmark: page.hasBookmark,
tags: page.tags,
Expand Down
3 changes: 0 additions & 3 deletions src/search/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
11 changes: 10 additions & 1 deletion src/search/search-index-new/util.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/search/search-index-old/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) : [],
Expand Down

0 comments on commit d2dcb45

Please sign in to comment.