add elastic scroll time in the env var

This commit is contained in:
Hongbo Wu
2023-09-22 13:51:53 +08:00
parent 0912e7cf0f
commit 0ff9fdef04
5 changed files with 29 additions and 25 deletions

View File

@ -428,12 +428,12 @@ export const functionResolvers = {
// return await ctx.models.reaction.batchGetFromHighlight(id)
// },
async createdByMe(
highlight: { userId: string; createdByMe: boolean },
createdByMe(
highlight: { userId: string },
__: unknown,
ctx: WithDataSourcesContext
) {
return highlight.createdByMe || highlight.userId === ctx.uid
return highlight.userId === ctx.uid
},
},
// Reaction: {

View File

@ -15,7 +15,6 @@ import {
DeleteHighlightError,
DeleteHighlightErrorCode,
DeleteHighlightSuccess,
Highlight,
MergeHighlightError,
MergeHighlightErrorCode,
MergeHighlightSuccess,
@ -35,19 +34,7 @@ import {
updateHighlight,
} from '../../services/highlights'
import { analytics } from '../../utils/analytics'
import { authorized } from '../../utils/helpers'
const highlightDataToHighlight = (highlight: HighlightData): Highlight => ({
...highlight,
replies: [],
reactions: [],
type: highlight.highlightType,
createdByMe: false,
user: {
...highlight.user,
sharedArticles: [],
},
})
import { authorized, highlightDataToHighlight } from '../../utils/helpers'
export const createHighlightResolver = authorized<
CreateHighlightSuccess,

View File

@ -52,8 +52,16 @@ export const createHighlight = async (
pubsub = createPubSubClient()
) => {
const newHighlight = await authTrx(
async (tx) =>
tx.withRepository(highlightRepository).createAndSave(highlight),
async (tx) => {
const repo = tx.withRepository(highlightRepository)
const newHighlight = await repo.createAndSave(highlight)
return repo.findOneOrFail({
where: { id: newHighlight.id },
relations: {
user: true,
},
})
},
undefined,
userId
)
@ -79,7 +87,13 @@ export const mergeHighlights = async (
await highlightRepo.delete(highlightsToRemove)
return highlightRepo.createAndSave(highlightToAdd)
const newHighlight = await highlightRepo.createAndSave(highlightToAdd)
return highlightRepo.findOneOrFail({
where: { id: newHighlight.id },
relations: {
user: true,
},
})
})
await pubsub.entityCreated<CreateHighlightEvent>(
@ -105,6 +119,7 @@ export const updateHighlight = async (
where: { id: highlightId },
relations: {
libraryItem: true,
user: true,
},
})
})

View File

@ -18,7 +18,6 @@ import {
CreateArticleSuccess,
FeedArticle,
Highlight,
HighlightType,
PageType,
Profile,
Recommendation,
@ -198,12 +197,14 @@ export const errorHandler = async (
return result
}
const highlightDataToHighlight = (highlight: HighlightData): Highlight => ({
export const highlightDataToHighlight = (
highlight: HighlightData
): Highlight => ({
...highlight,
createdByMe: true,
createdByMe: false,
reactions: [],
replies: [],
type: highlight.highlightType as HighlightType,
type: highlight.highlightType,
user: userDataToUser(highlight.user),
})

View File

@ -19,6 +19,7 @@ ES_URL = os.getenv('ES_URL', 'http://localhost:9200')
ES_USERNAME = os.getenv('ES_USERNAME', 'elastic')
ES_PASSWORD = os.getenv('ES_PASSWORD', 'password')
ES_SCAN_SIZE = os.getenv('ES_SCAN_SIZE', 1000)
ES_SCROLL_TIME = os.getenv('ES_SCROLL_TIME', '2m')
ES_INDEX = os.getenv('ES_INDEX', 'pages_alias')
CUT_OFF_DATE = os.getenv('CUT_OFF_DATE', '2000-01-01')
@ -312,7 +313,7 @@ async def main():
# Scan API for larger library
docs = async_scan(es_client, index=ES_INDEX, query=query,
preserve_order=True, size=ES_SCAN_SIZE,
request_timeout=60, scroll='2m')
request_timeout=60, scroll=ES_SCROLL_TIME)
# convert _id to uuid
async for doc in docs: