-
Notifications
You must be signed in to change notification settings - Fork 14
feat: add api for index #946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
67babe1
z
everpcpc 6a43ee4
z
everpcpc cd346fe
z
everpcpc 9ed49dc
Merge branch 'master' into feat-index
everpcpc 919c374
z
everpcpc 67f2a2d
Merge remote-tracking branch 'origin/feat-index' into feat-index
everpcpc b389660
Merge remote-tracking branch 'upstream/master' into feat-index
everpcpc a24171a
z
everpcpc bdd0ef1
z
everpcpc 99d2e09
z
everpcpc 6742d9b
z
everpcpc d931e8b
z
everpcpc 2c85333
z
everpcpc 346c41c
z
everpcpc 4e7fe04
z
everpcpc cd1ed7f
z
everpcpc 664698e
Merge remote-tracking branch 'upstream/master' into feat-index
everpcpc acd600e
z
everpcpc e8af42d
Merge branch 'master' into feat-index
everpcpc 3c48860
Merge branch 'master' into feat-index
everpcpc 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export function getSlimCacheKey(id: number): string { | ||
return `idx:v3:slim:${id}`; | ||
return `idx:v4:slim:${id}`; | ||
} |
This file contains hidden or 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,12 @@ | ||
export enum IndexType { | ||
User = 0, | ||
Public = 1, | ||
Award = 2, | ||
} | ||
|
||
export enum IndexRelatedCategory { | ||
Subject = 0, | ||
Character = 1, | ||
Person = 2, | ||
Ep = 3, | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -527,6 +527,37 @@ async function fetchEpisodeItemByID(episodeID: number): Promise<res.IEpisode | u | |
return item; | ||
} | ||
|
||
/** Cached */ | ||
export async function fetchSlimEpisodesByIDs( | ||
episodeIDs: number[], | ||
): Promise<Record<number, res.IEpisode>> { | ||
const cached = await redis.mget(episodeIDs.map((id) => getSubjectEpCacheKey(id))); | ||
const result: Record<number, res.IEpisode> = {}; | ||
const missing = []; | ||
for (const [idx, id] of episodeIDs.entries()) { | ||
if (cached[idx]) { | ||
const item = JSON.parse(cached[idx]) as res.IEpisode; | ||
item.desc = undefined; | ||
result[id] = item; | ||
} else { | ||
missing.push(id); | ||
} | ||
} | ||
if (missing.length > 0) { | ||
const data = await db | ||
.select() | ||
.from(schema.chiiEpisodes) | ||
.where(op.inArray(schema.chiiEpisodes.id, missing)); | ||
for (const d of data) { | ||
const item = convert.toEpisode(d); | ||
await redis.setex(getSubjectEpCacheKey(d.id), ONE_MONTH, JSON.stringify(item)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 一个月是不是久了点 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 也还好吧,有清理逻辑的 |
||
item.desc = undefined; | ||
result[d.id] = item; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
/** Cached */ | ||
export async function fetchSlimCharacterByID( | ||
id: number, | ||
|
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.