From 470861ed091314e71f3ac586244b82fd094a36dc Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Sat, 26 Oct 2024 01:29:19 +0700 Subject: [PATCH] UBERF-8539: Do not store TypingInfo into memdb (#7043) Signed-off-by: Andrey Sobolev --- models/chunter/src/index.ts | 14 +++++++++----- models/core/src/core.ts | 11 +++++++++-- models/core/src/index.ts | 6 ++++-- packages/core/src/classes.ts | 10 +++++++++- packages/core/src/component.ts | 4 +++- server/core/src/mem.ts | 24 +++++++++++++++++++++--- 6 files changed, 55 insertions(+), 14 deletions(-) diff --git a/models/chunter/src/index.ts b/models/chunter/src/index.ts index b8bb7da2ca..a59cb8b959 100644 --- a/models/chunter/src/index.ts +++ b/models/chunter/src/index.ts @@ -15,30 +15,30 @@ import activity, { type ActivityMessageControl } from '@hcengineering/activity' import { chunterId, type ChunterSpace } from '@hcengineering/chunter' -import presentation from '@hcengineering/model-presentation' +import contact from '@hcengineering/contact' import { type Builder } from '@hcengineering/model' import core from '@hcengineering/model-core' +import presentation from '@hcengineering/model-presentation' import view from '@hcengineering/model-view' import workbench from '@hcengineering/model-workbench' import { WidgetType } from '@hcengineering/workbench' -import contact from '@hcengineering/contact' -import chunter from './plugin' import { defineActions } from './actions' import { defineNotifications } from './notifications' +import chunter from './plugin' import { DOMAIN_CHUNTER, TChannel, TChatMessage, TChatMessageViewlet, TChatSyncInfo, + TChunterExtension, TChunterSpace, TDirectMessage, TInlineButton, TObjectChatPanel, TThreadMessage, - TTypingInfo, - TChunterExtension + TTypingInfo } from './types' export { chunterId } from '@hcengineering/chunter' @@ -161,6 +161,10 @@ export function createModel (builder: Builder): void { presenter: chunter.component.ThreadMessagePresenter }) + builder.mixin(chunter.class.TypingInfo, core.class.Class, core.mixin.TransientConfiguration, { + broadcastOnly: true + }) + builder.createDoc( view.class.Viewlet, core.space.Model, diff --git a/models/core/src/core.ts b/models/core/src/core.ts index 3942868da8..2cff517172 100644 --- a/models/core/src/core.ts +++ b/models/core/src/core.ts @@ -14,8 +14,6 @@ // import { - type Card, - type CollaborativeDoc, DOMAIN_BLOB, DOMAIN_CONFIGURATION, DOMAIN_DOC_INDEX_STATE, @@ -27,8 +25,10 @@ import { type ArrOf, type AttachedDoc, type Blob, + type Card, type Class, type ClassifierKind, + type CollaborativeDoc, type Collection, type Configuration, type ConfigurationElement, @@ -50,6 +50,7 @@ import { type RefTo, type Space, type Timestamp, + type TransientConfiguration, type Type, type TypeAny, type Version @@ -403,3 +404,9 @@ export class TTypeCollaborativeDocVersion extends TType {} @UX(core.string.Rank) @Model(core.class.TypeRank, core.class.Type) export class TTypeRank extends TType {} + +@MMixin(core.mixin.TransientConfiguration, core.class.Class) +export class TTransientConfiguration extends TClass implements TransientConfiguration { + @Prop(TypeBoolean(), core.string.Private) + broadcastOnly!: boolean +} diff --git a/models/core/src/index.ts b/models/core/src/index.ts index 0ef71c7ae9..e7dfc70eca 100644 --- a/models/core/src/index.ts +++ b/models/core/src/index.ts @@ -39,12 +39,12 @@ import { TAttachedDoc, TAttribute, TBlob, + TCard, TClass, TCollection, TConfiguration, TConfigurationElement, TDoc, - TCard, TDocIndexState, TDomainIndexConfiguration, TEnum, @@ -57,6 +57,7 @@ import { TObj, TPluginConfiguration, TRefTo, + TTransientConfiguration, TType, TTypeAny, TTypeBlob, @@ -173,7 +174,8 @@ export function createModel (builder: Builder): void { TMigrationState, TBlob, TDomainIndexConfiguration, - TBenchmarkDoc + TBenchmarkDoc, + TTransientConfiguration ) builder.createDoc( diff --git a/packages/core/src/classes.ts b/packages/core/src/classes.ts index c64aa82119..3c37f52773 100644 --- a/packages/core/src/classes.ts +++ b/packages/core/src/classes.ts @@ -15,8 +15,8 @@ // import type { Asset, IntlString, Plugin } from '@hcengineering/platform' -import type { DocumentQuery } from './storage' import { CollaborativeDoc } from './collaboration' +import type { DocumentQuery } from './storage' /** * @public @@ -346,6 +346,14 @@ export const DOMAIN_MIGRATION = '_migrations' as Domain */ export const DOMAIN_TRANSIENT = 'transient' as Domain +/** + * @public + */ +export interface TransientConfiguration extends Class { + // If set will not store transient objects into memdb + broadcastOnly: boolean +} + /** * Special domain to access s3 blob data. * @public diff --git a/packages/core/src/component.ts b/packages/core/src/component.ts index 5349a3a8c2..baed6b65de 100644 --- a/packages/core/src/component.ts +++ b/packages/core/src/component.ts @@ -48,6 +48,7 @@ import type { SpaceTypeDescriptor, SystemSpace, Timestamp, + TransientConfiguration, Type, TypeAny, TypedSpace, @@ -148,7 +149,8 @@ export default plugin(coreId, { mixin: { ConfigurationElement: '' as Ref>, IndexConfiguration: '' as Ref>>, - SpacesTypeData: '' as Ref> + SpacesTypeData: '' as Ref>, + TransientConfiguration: '' as Ref> }, space: { Tx: '' as Ref, diff --git a/server/core/src/mem.ts b/server/core/src/mem.ts index 8b615044d6..5f113d8e42 100644 --- a/server/core/src/mem.ts +++ b/server/core/src/mem.ts @@ -30,10 +30,12 @@ import core, { type StorageIterator, toFindResult, type Tx, + type TxCUD, + TxProcessor, type TxResult, type WorkspaceId } from '@hcengineering/core' -import { type DbAdapterHandler, type DbAdapter, type DomainHelperOperations } from './adapter' +import { type DbAdapter, type DbAdapterHandler, type DomainHelperOperations } from './adapter' /** * @public @@ -119,7 +121,7 @@ export class DummyDbAdapter implements DbAdapter { class InMemoryAdapter extends DummyDbAdapter implements DbAdapter { private readonly modeldb: ModelDb - constructor (hierarchy: Hierarchy) { + constructor (readonly hierarchy: Hierarchy) { super() this.modeldb = new ModelDb(hierarchy) } @@ -138,7 +140,23 @@ class InMemoryAdapter extends DummyDbAdapter implements DbAdapter { } async tx (ctx: MeasureContext, ...tx: Tx[]): Promise { - return await this.modeldb.tx(...tx) + // Filter transactions with broadcast only flags + const ftx = tx.filter((it) => { + if (TxProcessor.isExtendsCUD(it._class)) { + const cud = it as TxCUD + const objClass = this.hierarchy.getClass(cud.objectClass) + const mix = this.hierarchy.hasMixin(objClass, core.mixin.TransientConfiguration) + if (mix && this.hierarchy.as(objClass, core.mixin.TransientConfiguration).broadcastOnly) { + // We do not need to store a broadcast only transactions into model. + return false + } + } + return true + }) + if (ftx.length === 0) { + return [] + } + return await this.modeldb.tx(...ftx) } }