mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-14 04:08:19 +00:00
digest attribute fix (#5914)
Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
parent
ff96ce1497
commit
a7bec96320
@ -158,6 +158,7 @@ export interface IndexKeyOptions {
|
|||||||
_class?: Ref<Class<Obj>>
|
_class?: Ref<Class<Obj>>
|
||||||
docId?: Ref<DocIndexState>
|
docId?: Ref<DocIndexState>
|
||||||
extra?: string[]
|
extra?: string[]
|
||||||
|
digest?: boolean
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
@ -171,7 +172,8 @@ export function docUpdKey (name: string, opt?: IndexKeyOptions): string {
|
|||||||
*/
|
*/
|
||||||
export function docKey (name: string, opt?: IndexKeyOptions): string {
|
export function docKey (name: string, opt?: IndexKeyOptions): string {
|
||||||
const extra = opt?.extra !== undefined && opt?.extra?.length > 0 ? `#${opt.extra?.join('#') ?? ''}` : ''
|
const extra = opt?.extra !== undefined && opt?.extra?.length > 0 ? `#${opt.extra?.join('#') ?? ''}` : ''
|
||||||
return opt?._class === undefined ? name : `${opt?._class}%${name}${extra}`
|
const digestName = opt?.digest === true ? name + '^digest' : name
|
||||||
|
return opt?._class === undefined ? digestName : `${opt?._class}%${digestName}${extra}`
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -182,6 +184,7 @@ export function extractDocKey (key: string): {
|
|||||||
attr: string
|
attr: string
|
||||||
docId?: Ref<DocIndexState>
|
docId?: Ref<DocIndexState>
|
||||||
extra: string[]
|
extra: string[]
|
||||||
|
digest: boolean
|
||||||
} {
|
} {
|
||||||
let k = key
|
let k = key
|
||||||
if (k.startsWith(attributesPrefix)) {
|
if (k.startsWith(attributesPrefix)) {
|
||||||
@ -204,8 +207,14 @@ export function extractDocKey (key: string): {
|
|||||||
}
|
}
|
||||||
const extra = attr.split('#')
|
const extra = attr.split('#')
|
||||||
attr = extra.splice(0, 1)[0]
|
attr = extra.splice(0, 1)[0]
|
||||||
|
const digestPos = attr.indexOf('^digest')
|
||||||
|
let digest = false
|
||||||
|
if (digestPos !== -1) {
|
||||||
|
attr = attr.substring(0, digestPos)
|
||||||
|
digest = true
|
||||||
|
}
|
||||||
|
|
||||||
return { docId, attr, _class, extra }
|
return { docId, attr, _class, extra, digest }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,7 +49,6 @@ export class CollaborativeContentRetrievalStage implements FullTextPipelineStage
|
|||||||
stageId = contentStageId
|
stageId = contentStageId
|
||||||
|
|
||||||
extra = ['content', 'base64']
|
extra = ['content', 'base64']
|
||||||
digest = '^digest'
|
|
||||||
|
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|
||||||
@ -111,7 +110,7 @@ export class CollaborativeContentRetrievalStage implements FullTextPipelineStage
|
|||||||
|
|
||||||
if (docInfo !== undefined) {
|
if (docInfo !== undefined) {
|
||||||
const digest = docInfo.etag
|
const digest = docInfo.etag
|
||||||
const digestKey = docKey(val.name + this.digest, { _class: val.attributeOf })
|
const digestKey = docKey(val.name, { _class: val.attributeOf, digest: true })
|
||||||
if (doc.attributes[digestKey] !== digest) {
|
if (doc.attributes[digestKey] !== digest) {
|
||||||
;(update as any)[docUpdKey(digestKey)] = digest
|
;(update as any)[docUpdKey(digestKey)] = digest
|
||||||
|
|
||||||
|
@ -46,7 +46,6 @@ export class ContentRetrievalStage implements FullTextPipelineStage {
|
|||||||
stageId = contentStageId
|
stageId = contentStageId
|
||||||
|
|
||||||
extra = ['content', 'base64']
|
extra = ['content', 'base64']
|
||||||
digest = '^digest'
|
|
||||||
|
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|
||||||
@ -110,7 +109,7 @@ export class ContentRetrievalStage implements FullTextPipelineStage {
|
|||||||
|
|
||||||
if (!contentType.includes('image')) {
|
if (!contentType.includes('image')) {
|
||||||
const digest = docInfo.etag
|
const digest = docInfo.etag
|
||||||
const digestKey = docKey(val.name + this.digest, { _class: val.attributeOf })
|
const digestKey = docKey(val.name, { _class: val.attributeOf, digest: true })
|
||||||
if (doc.attributes[digestKey] !== digest) {
|
if (doc.attributes[digestKey] !== digest) {
|
||||||
;(update as any)[docUpdKey(digestKey)] = digest
|
;(update as any)[docUpdKey(digestKey)] = digest
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ function updateDoc2Elastic (
|
|||||||
if (v == null) {
|
if (v == null) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
let { _class, attr, docId, extra } = extractDocKey(k)
|
let { _class, attr, docId, extra, digest } = extractDocKey(k)
|
||||||
if (attr.length === 0) {
|
if (attr.length === 0) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -302,7 +302,7 @@ function updateDoc2Elastic (
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const docIdAttr = docKey(attr, { _class, extra: extra.filter((it) => it !== 'base64') })
|
const docIdAttr = docKey(attr, { _class, extra: extra.filter((it) => it !== 'base64'), digest })
|
||||||
if (vv !== null) {
|
if (vv !== null) {
|
||||||
// Since we replace array of values, we could ignore null
|
// Since we replace array of values, we could ignore null
|
||||||
doc[docIdAttr] =
|
doc[docIdAttr] =
|
||||||
|
Loading…
Reference in New Issue
Block a user