Skip to content

Commit

Permalink
Revert "feat: create index for path base search (#1401)"
Browse files Browse the repository at this point in the history
This reverts commit 2602c07.
  • Loading branch information
farnabaz authored Aug 4, 2022
1 parent 2602c07 commit 1afb37c
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 66 deletions.
6 changes: 1 addition & 5 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,12 @@ export default defineNuxtModule<ModuleOptions>({
nitro.options.runtimeConfig.public.content.wsUrl = url.replace('http', 'ws')

// Watch contents
await nitro.storage.watch(async (event: WatchEvent, key: string) => {
await nitro.storage.watch((event: WatchEvent, key: string) => {
// Ignore events that are not related to content
if (!key.startsWith(MOUNT_PREFIX)) {
return
}
key = key.substring(MOUNT_PREFIX.length)

// Remove content Index
await nitro.storage.removeItem('cache:content:content-index.json')

// Broadcast a message to the server to refresh the page
ws.broadcast({ event, key })
})
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const createQueryFetch = <T = ParsedContent>(path?: string) => (query: Qu
})
}

return $fetch(apiPath as any, {
return $fetch<T | T[]>(apiPath as any, {
method: 'GET',
responseType: 'json',
params: {
Expand Down
9 changes: 1 addition & 8 deletions src/runtime/server/api/cache.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import { defineEventHandler } from 'h3'
import { getContentIndex } from '../content-index'
import { cacheStorage, serverQueryContent } from '../storage'
import { serverQueryContent } from '../storage'

// This route is used to cache all the parsed content
export default defineEventHandler(async (event) => {
const now = Date.now()
// Fetch all content
await serverQueryContent(event).find()

// Generate Index
await getContentIndex(event)

const navigation = await $fetch('/api/_content/navigation')
await cacheStorage.setItem('content-navigation.json', navigation)

return {
generatedAt: now,
generateTime: Date.now() - now
Expand Down
11 changes: 1 addition & 10 deletions src/runtime/server/api/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import { defineEventHandler } from 'h3'
import { cacheStorage, serverQueryContent } from '../storage'
import { serverQueryContent } from '../storage'
import { createNav } from '../navigation'
import { ParsedContentMeta } from '../../types'
import { getContentQuery } from '../../utils/query'
import { isPreview } from '../preview'

export default defineEventHandler(async (event) => {
const query = getContentQuery(event)

// Read from cache if not preview and there is no query
if (!isPreview(event) && Object.keys(query).length === 0) {
const cache = cacheStorage.getItem('content-navigation.json')
if (cache) {
return cache
}
}

const contents = await serverQueryContent(event, query)
.where({
/**
Expand Down
39 changes: 0 additions & 39 deletions src/runtime/server/content-index.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/runtime/server/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { createPipelineFetcher } from '../query/match/pipeline'
import { transformContent } from '../transformers'
import type { ModuleOptions } from '../../module'
import { getPreview, isPreview } from './preview'
import { getIndexedContentsList } from './content-index'
// eslint-disable-next-line import/named
// @ts-ignore
import { useNitroApp, useRuntimeConfig, useStorage } from '#imports'
Expand Down Expand Up @@ -201,7 +200,9 @@ export const createServerQueryFetch = <T = ParsedContent>(event: CompatibilityEv
query.sort({ _file: 1, $numeric: true })
}

return createPipelineFetcher<T>(() => getIndexedContentsList<T>(event, query))(query)
return createPipelineFetcher<T>(
() => getContentsList(event) as unknown as Promise<T[]>
)(query)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export interface QueryBuilder<T = ParsedContentMeta> {
/**
* Fetch sorround contents
*/
findSurround(query: string | QueryBuilderWhere, options?: Partial<{ before: number; after: number }>): Promise<Array<T>>
findSurround(query: string | object, options?: Partial<{ before: number; after: number }>): Promise<Array<T>>

/**
* Filter contents based on locale
Expand Down

0 comments on commit 1afb37c

Please sign in to comment.