This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: [SPMVP -6521] use typesense to fetch article list in karbon to reduce api server load #281
Merged
DanSnow
merged 9 commits into
main
from
SPMVP-6521-use-typesense-to-fetch-article-list-in-karbon-to-reduce-api-server-load
Oct 17, 2023
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3270149
feat: use Typesense get articles
SidStraw 7dfe7ff
feat: use Typesense get articles for sitemap
SidStraw 20deb04
feat: add typesense filter_by
SidStraw 53bb49b
feat: modify listFeedArticles filter fromat
SidStraw dce8cef
fix: wrong Typesense search query schema
SidStraw 2d849e5
fix: sitemap / feed
SidStraw 9639cef
refactor: fix deepSource issue
SidStraw a5e1860
fix: import listArticles from internal
SidStraw 4ace651
fix: article-filter by normalize article
SidStraw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/karbon/src/runtime/composables/typesense-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { SearchClient } from 'typesense' | ||
import { getStoripressConfig } from './storipress-base-client' | ||
|
||
let typesenseClient: SearchClient | ||
|
||
export function useTypesenseClient() { | ||
if (typesenseClient) return typesenseClient | ||
|
||
const storipress = getStoripressConfig() | ||
typesenseClient = new SearchClient({ | ||
nodes: [ | ||
{ | ||
host: storipress.searchDomain ?? '', | ||
port: 443, | ||
protocol: 'https', | ||
}, | ||
], | ||
apiKey: storipress.searchKey, | ||
connectionTimeoutSeconds: 5, | ||
}) | ||
return typesenseClient | ||
} | ||
|
||
export interface TypesenseFilter { | ||
desk_ids?: string[] | ||
author_ids?: string[] | ||
author_names?: string[] | ||
tag_ids?: string[] | ||
tag_names?: string[] | ||
} | ||
|
||
export const PER_PAGE = 100 | ||
|
||
export function getSearchQuery(page = 1, filter: TypesenseFilter = {}) { | ||
const { desk_ids, author_ids, author_names, tag_ids, tag_names } = filter | ||
let filterBy = 'published:=true' | ||
if (desk_ids?.length) filterBy += ` && desk_id:=[${desk_ids.join()}]` | ||
if (author_ids?.length) filterBy += ` && author_ids:=[${author_ids.join()}]` | ||
if (author_names?.length) filterBy += ` && author_names:=[${author_names.join()}]` | ||
if (tag_ids?.length) filterBy += ` && tag_ids:=[${tag_ids.join()}]` | ||
if (tag_names?.length) filterBy += ` && tag_names:=[${tag_names.join()}]` | ||
|
||
return { | ||
q: '*', | ||
sort_by: 'published_at:desc,order:asc', | ||
filter_by: filterBy, | ||
per_page: PER_PAGE, | ||
page, | ||
query_by: 'title', | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 這樣整理出來我覺得是很好的設計