Skip to content

Commit

Permalink
UBER-942: Rework skill optimization
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
  • Loading branch information
haiodo committed Nov 7, 2023
1 parent 429574c commit 6316c5b
Show file tree
Hide file tree
Showing 41 changed files with 1,061 additions and 245 deletions.
3 changes: 3 additions & 0 deletions models/core/src/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ export class TTxApplyIf extends TTx implements TxApplyIf {
// All matches should be false for all documents.
notMatch!: DocumentClassQuery<Doc>[]
txes!: TxCUD<Doc>[]

notify!: boolean
extraNotify!: Ref<Class<Doc>>[]
}

@Model(core.class.TxWorkspaceEvent, core.class.Doc)
Expand Down
22 changes: 22 additions & 0 deletions models/recruit/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ export const recruitOperation: MigrateOperation = {
}
})
}
},
{
state: 'wrong-categories',
func: async (client): Promise<void> => {
const ops = new TxOperations(client, core.account.System)
while (true) {
const docs = await ops.findAll(
tags.class.TagElement,
{
targetClass: recruit.mixin.Candidate,
category: { $in: [tracker.category.Other, 'document:category:Other' as Ref<TagCategory>] }
},
{ limit: 1000 }
)
for (const d of docs) {
await ops.update(d, { category: recruit.category.Other })
}
if (docs.length === 0) {
break
}
}
}
}
])
}
Expand Down
4 changes: 2 additions & 2 deletions models/server-tracker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export function createModel (builder: Builder): void {
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverTracker.trigger.OnComponentRemove,
txMatch: {
_class: core.class.TxCollectionCUD,
'tx._class': core.class.TxCreateDoc
_class: core.class.TxRemoveDoc,
objectClass: tracker.class.Component
}
})

Expand Down
12 changes: 10 additions & 2 deletions packages/core/src/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,18 @@ export class ApplyOperations extends TxOperations {
return this
}

async commit (): Promise<boolean> {
async commit (notify: boolean = true, extraNotify: Ref<Class<Doc>>[] = []): Promise<boolean> {
if (this.txes.length > 0) {
return await ((await this.ops.tx(
this.ops.txFactory.createTxApplyIf(core.space.Tx, this.scope, this.matches, this.notMatches, this.txes)
this.ops.txFactory.createTxApplyIf(
core.space.Tx,
this.scope,
this.matches,
this.notMatches,
this.txes,
notify,
extraNotify
)
)) as Promise<boolean>)
}
return true
Expand Down
25 changes: 21 additions & 4 deletions packages/core/src/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@ export enum WorkspaceEvent {
Upgrade,
IndexingUpdate,
SecurityChange,
MaintenanceNotification
MaintenanceNotification,
BulkUpdate
}

/**
* Event to be send by server during model upgrade procedure.
* @public
*/
export interface TxWorkspaceEvent extends Tx {
export interface TxWorkspaceEvent<T = any> extends Tx {
event: WorkspaceEvent
params: any
params: T
}

/**
Expand All @@ -70,6 +71,13 @@ export interface IndexingUpdateEvent {
_class: Ref<Class<Doc>>[]
}

/**
* @public
*/
export interface BulkUpdateEvent {
_class: Ref<Class<Doc>>[]
}

/**
* @public
*/
Expand Down Expand Up @@ -125,6 +133,11 @@ export interface TxApplyIf extends Tx {

// If all matched execute following transactions.
txes: TxCUD<Doc>[]

notify?: boolean // If false will not send notifications.

// If passed, will send WorkspaceEvent.BulkUpdate event with list of classes to update
extraNotify?: Ref<Class<Doc>>[]
}

/**
Expand Down Expand Up @@ -591,6 +604,8 @@ export class TxFactory {
match: DocumentClassQuery<Doc>[],
notMatch: DocumentClassQuery<Doc>[],
txes: TxCUD<Doc>[],
notify: boolean = true,
extraNotify: Ref<Class<Doc>>[] = [],
modifiedOn?: Timestamp,
modifiedBy?: Ref<Account>
): TxApplyIf {
Expand All @@ -604,7 +619,9 @@ export class TxFactory {
scope,
match,
notMatch,
txes
txes,
notify,
extraNotify
}
}
}
18 changes: 12 additions & 6 deletions packages/presentation/src/components/DocPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
IconCheck,
IconSearch,
ListView,
Spinner,
createFocusManager,
deviceOptionsStore,
resizeObserver,
Expand Down Expand Up @@ -59,6 +60,7 @@
export let disallowDeselect: Ref<Doc>[] | undefined = undefined
export let created: Doc[] = []
export let embedded: boolean = false
export let loading = false
let search: string = ''
Expand Down Expand Up @@ -185,7 +187,7 @@
icon={IconAdd}
showTooltip={{ label: create.label }}
on:click={onCreate}
disabled={readonly}
disabled={readonly || loading}
/>
</div>
{/if}
Expand All @@ -210,20 +212,24 @@
{@const isDeselectDisabled = selectedElements.has(obj._id) && forbiddenDeselectItemIds.has(obj._id)}
<button
class="menu-item withList w-full flex-row-center"
disabled={readonly || isDeselectDisabled}
disabled={readonly || isDeselectDisabled || loading}
on:click={() => {
handleSelection(undefined, objects, item)
}}
>
<span class="label" class:disabled={readonly || isDeselectDisabled}>
<span class="label" class:disabled={readonly || isDeselectDisabled || loading}>
<slot name="item" item={obj} />
</span>
{#if (allowDeselect && selected) || multiSelect || selected}
<div class="check" class:disabled={readonly}>
{#if obj._id === selected || selectedElements.has(obj._id)}
<div use:tooltip={{ label: titleDeselect ?? presentation.string.Deselect }}>
<Icon icon={IconCheck} size={'small'} />
</div>
{#if loading}
<Spinner size={'small'} />
{:else}
<div use:tooltip={{ label: titleDeselect ?? presentation.string.Deselect }}>
<Icon icon={IconCheck} size={'small'} />
</div>
{/if}
{/if}
</div>
{/if}
Expand Down
4 changes: 3 additions & 1 deletion packages/presentation/src/components/ObjectPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import type { Class, Doc, DocumentQuery, FindOptions, Ref } from '@hcengineering/core'
import type { IntlString } from '@hcengineering/platform'
import { Label } from '@hcengineering/ui'
import { createEventDispatcher } from 'svelte'
import presentation from '..'
import { ObjectCreate } from '../types'
import { createQuery } from '../utils'
import DocPopup from './DocPopup.svelte'
import { createEventDispatcher } from 'svelte'
export let _class: Ref<Class<Doc>>
export let options: FindOptions<Doc> | undefined = undefined
Expand All @@ -47,6 +47,7 @@
export let readonly = false
export let disallowDeselect: Ref<Doc>[] | undefined = undefined
export let embedded: boolean = false
export let loading = false
export let filter: (it: Doc) => boolean = () => {
return true
Expand Down Expand Up @@ -110,6 +111,7 @@
{readonly}
{disallowDeselect}
{embedded}
{loading}
on:update
on:close
on:changeContent
Expand Down
26 changes: 26 additions & 0 deletions packages/query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import core, {
getObjectValue,
Hierarchy,
IndexingUpdateEvent,
BulkUpdateEvent,
Lookup,
LookupData,
matchQuery,
Expand Down Expand Up @@ -1034,6 +1035,31 @@ export class LiveQuery extends TxProcessor implements Client {
}
}
}
if (evt.event === WorkspaceEvent.BulkUpdate) {
const params = evt.params as BulkUpdateEvent
for (const q of [...this.queue]) {
if (params._class.includes(q._class)) {
if (!this.removeFromQueue(q)) {
try {
await this.refresh(q)
} catch (err) {
console.error(err)
}
}
}
}
for (const v of this.queries.values()) {
for (const q of v) {
if (params._class.includes(q._class)) {
try {
await this.refresh(q)
} catch (err) {
console.error(err)
}
}
}
}
}
}

private async changePrivateHandler (tx: Tx): Promise<void> {
Expand Down
39 changes: 24 additions & 15 deletions packages/ui/src/components/EditWithIcon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import Icon from './Icon.svelte'
import Button from './Button.svelte'
import IconClose from './icons/Close.svelte'
import Spinner from './Spinner.svelte'
export let icon: Asset | AnySvelteComponent | ComponentType
export let width: string | undefined = undefined
Expand All @@ -29,6 +30,7 @@
export let placeholderParam: any | undefined = undefined
export let autoFocus: boolean = false
export let size: 'small' | 'medium' | 'large' = 'medium'
export let loading = false
const dispatch = createEventDispatcher()
let textHTML: HTMLInputElement
Expand All @@ -52,21 +54,28 @@
<div class="mr-2 content-dark-color"><Icon {icon} size={'small'} /></div>
<input bind:this={textHTML} type="text" bind:value placeholder={phTraslate} on:change on:input on:keydown />
<slot name="extra" />
{#if value}
<div class="ml-2">
<Button
icon={IconClose}
kind={'ghost'}
size={'small'}
noFocus
on:click={() => {
value = ''
dispatch('change', '')
textHTML.focus()
}}
/>
</div>
{/if}
<div class="flex-row-center">
{#if value}
<div class="ml-2">
<Button
icon={IconClose}
kind={'ghost'}
size={'small'}
noFocus
on:click={() => {
value = ''
dispatch('change', '')
textHTML.focus()
}}
/>
</div>
{/if}
{#if loading}
<div class="ml-1 mr-2">
<Spinner size={'medium'} />
</div>
{/if}
</div>
</div>

<style lang="scss">
Expand Down
24 changes: 12 additions & 12 deletions packages/ui/src/components/PopupInstance.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@
class:anim={element === 'float' || element === 'centered'}
bind:this={modalHTML}
style={`z-index: ${zIndex + 1};`}
style:top={options.props.top}
style:bottom={options.props.bottom}
style:left={options.props.left}
style:right={options.props.right}
style:width={options.props.width}
style:height={options.props.height}
style:max-width={options.props.maxWidth}
style:max-height={options.props.maxHeight}
style:min-width={options.props.minWidth}
style:min-height={options.props.minHeight}
style:transform={options.props.transform}
style:top={options?.props?.top}
style:bottom={options?.props?.bottom}
style:left={options?.props?.left}
style:right={options?.props?.right}
style:width={options?.props?.width}
style:height={options?.props?.height}
style:max-width={options?.props?.maxWidth}
style:max-height={options?.props?.maxHeight}
style:min-width={options?.props?.minWidth}
style:min-height={options?.props?.minHeight}
style:transform={options?.props?.transform}
use:resizeObserver={(element) => {
clientWidth = element.clientWidth
clientHeight = element.clientHeight
Expand Down Expand Up @@ -187,7 +187,7 @@
{#if overlay}
<div
class="modal-overlay"
class:antiOverlay={options.showOverlay}
class:antiOverlay={options?.showOverlay}
style={`z-index: ${zIndex};`}
on:click={handleOverlayClick}
on:keydown|stopPropagation|preventDefault={() => {}}
Expand Down
Loading

0 comments on commit 6316c5b

Please sign in to comment.