Merge remote-tracking branch 'origin/develop' into staging

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2024-10-22 22:27:12 +07:00
commit 86191696d0
No known key found for this signature in database
GPG Key ID: BD80F68D68D8F7F2
30 changed files with 247 additions and 187 deletions

6
.vscode/launch.json vendored
View File

@ -118,9 +118,9 @@
"args": ["src/__start.ts"], "args": ["src/__start.ts"],
"env": { "env": {
"MONGO_URL": "mongodb://localhost:27017", "MONGO_URL": "mongodb://localhost:27017",
// "DB_URL": "mongodb://localhost:27017", "DB_URL": "mongodb://localhost:27017",
"REGION": "pg", "REGION": "",
"DB_URL": "postgresql://postgres:example@localhost:5432", // "DB_URL": "postgresql://postgres:example@localhost:5432",
"SERVER_SECRET": "secret", "SERVER_SECRET": "secret",
"TRANSACTOR_URL": "ws://localhost:3333", "TRANSACTOR_URL": "ws://localhost:3333",
"ACCOUNTS_URL": "http://localhost:3000", "ACCOUNTS_URL": "http://localhost:3000",

View File

@ -115,10 +115,9 @@ services:
- MODEL_ENABLED=* - MODEL_ENABLED=*
- ACCOUNTS_URL=http://host.docker.internal:3000 - ACCOUNTS_URL=http://host.docker.internal:3000
- BRANDING_PATH=/var/cfg/branding.json - BRANDING_PATH=/var/cfg/branding.json
- NOTIFY_INBOX_ONLY=true
# - PARALLEL=2 # - PARALLEL=2
# - INIT_SCRIPT_URL=https://raw.githubusercontent.com/hcengineering/init/main/script.yaml - INIT_SCRIPT_URL=https://raw.githubusercontent.com/hcengineering/init/main/script.yaml
# - INIT_WORKSPACE=onboarding - INIT_WORKSPACE=test
restart: unless-stopped restart: unless-stopped
workspacepg: workspacepg:
image: hardcoreeng/workspace image: hardcoreeng/workspace
@ -142,7 +141,7 @@ services:
- ACCOUNTS_URL=http://host.docker.internal:3000 - ACCOUNTS_URL=http://host.docker.internal:3000
- BRANDING_PATH=/var/cfg/branding.json - BRANDING_PATH=/var/cfg/branding.json
# - PARALLEL=2 # - PARALLEL=2
# - INIT_SCRIPT_URL=https://raw.githubusercontent.com/hcengineering/init/main/script.yaml - INIT_SCRIPT_URL=https://raw.githubusercontent.com/hcengineering/init/main/script.yaml
# - INIT_WORKSPACE=onboarding # - INIT_WORKSPACE=onboarding
restart: unless-stopped restart: unless-stopped
collaborator: collaborator:

View File

@ -72,8 +72,6 @@ async function processFixJsonMarkupFor (
db: Db, db: Db,
storageAdapter: StorageAdapter storageAdapter: StorageAdapter
): Promise<void> { ): Promise<void> {
console.log('processing', domain, _class)
const collection = db.collection<Doc>(domain) const collection = db.collection<Doc>(domain)
const docs = await collection.find({ _class }).toArray() const docs = await collection.find({ _class }).toArray()
for (const doc of docs) { for (const doc of docs) {
@ -119,8 +117,6 @@ async function processFixJsonMarkupFor (
} }
} }
} }
console.log('...processed', docs.length)
} }
export async function migrateMarkup ( export async function migrateMarkup (
@ -151,12 +147,9 @@ export async function migrateMarkup (
const collection = workspaceDb.collection(domain) const collection = workspaceDb.collection(domain)
const filter = hierarchy.isMixin(_class) ? { [_class]: { $exists: true } } : { _class } const filter = hierarchy.isMixin(_class) ? { [_class]: { $exists: true } } : { _class }
const count = await collection.countDocuments(filter)
const iterator = collection.find<Doc>(filter) const iterator = collection.find<Doc>(filter)
try { try {
console.log('processing', _class, '->', count)
await processMigrateMarkupFor(ctx, hierarchy, storageAdapter, workspaceId, attributes, iterator, concurrency) await processMigrateMarkupFor(ctx, hierarchy, storageAdapter, workspaceId, attributes, iterator, concurrency)
} finally { } finally {
await iterator.close() await iterator.close()

View File

@ -67,7 +67,6 @@ async function processMigrateMarkupFor (
client: MigrationClient, client: MigrationClient,
iterator: MigrationIterator<DocUpdateMessage> iterator: MigrationIterator<DocUpdateMessage>
): Promise<void> { ): Promise<void> {
let processed = 0
while (true) { while (true) {
const docs = await iterator.next(1000) const docs = await iterator.next(1000)
if (docs === null || docs.length === 0) { if (docs === null || docs.length === 0) {
@ -104,9 +103,6 @@ async function processMigrateMarkupFor (
if (ops.length > 0) { if (ops.length > 0) {
await client.bulk(DOMAIN_ACTIVITY, ops) await client.bulk(DOMAIN_ACTIVITY, ops)
} }
processed += docs.length
console.log('...processed', processed)
} }
} }

View File

@ -53,7 +53,6 @@ async function processMigrateMarkupFor (
client: MigrationClient, client: MigrationClient,
iterator: MigrationIterator<Doc> iterator: MigrationIterator<Doc>
): Promise<void> { ): Promise<void> {
let processed = 0
while (true) { while (true) {
const docs = await iterator.next(1000) const docs = await iterator.next(1000)
if (docs === null || docs.length === 0) { if (docs === null || docs.length === 0) {
@ -88,9 +87,6 @@ async function processMigrateMarkupFor (
if (operations.length > 0) { if (operations.length > 0) {
await client.bulk(domain, operations) await client.bulk(domain, operations)
} }
processed += docs.length
console.log('...processed', processed)
} }
} }
@ -122,7 +118,6 @@ async function processFixMigrateMarkupFor (
client: MigrationClient, client: MigrationClient,
iterator: MigrationIterator<Doc> iterator: MigrationIterator<Doc>
): Promise<void> { ): Promise<void> {
let processed = 0
while (true) { while (true) {
const docs = await iterator.next(1000) const docs = await iterator.next(1000)
if (docs === null || docs.length === 0) { if (docs === null || docs.length === 0) {
@ -164,9 +159,6 @@ async function processFixMigrateMarkupFor (
if (operations.length > 0) { if (operations.length > 0) {
await client.bulk(domain, operations) await client.bulk(domain, operations)
} }
processed += docs.length
console.log('...processed', processed)
} }
} }

View File

@ -14,7 +14,7 @@
--> -->
<script lang="ts"> <script lang="ts">
import type { IntlString, Asset } from '@hcengineering/platform' import type { IntlString, Asset } from '@hcengineering/platform'
import { createEventDispatcher, ComponentType } from 'svelte' import { createEventDispatcher, ComponentType, afterUpdate } from 'svelte'
import { DateRangeMode } from '@hcengineering/core' import { DateRangeMode } from '@hcengineering/core'
import ui from '../../plugin' import ui from '../../plugin'
@ -86,6 +86,7 @@
focusManager?.setFocus(idx) focusManager?.setFocus(idx)
}) })
} }
afterUpdate(() => dispatch('resize', input?.clientWidth))
</script> </script>
<button <button

View File

@ -75,6 +75,7 @@
{width} {width}
{shouldIgnoreOverdue} {shouldIgnoreOverdue}
on:change={handleDueDateChanged} on:change={handleDueDateChanged}
on:resize
/> />
</div> </div>
{/if} {/if}

View File

@ -49,18 +49,32 @@
let allWidth: number let allWidth: number
const widths: number[] = [] const widths: number[] = []
const elements: HTMLDivElement[] = []
afterUpdate(() => { afterUpdate(() => {
let count: number = 0 let count: number = 0
widths.forEach((i) => (count += i)) widths.forEach((i) => (count += i))
full = count > allWidth full = count > allWidth
dispatch('change', { full, ckeckFilled }) dispatch('change', { full, ckeckFilled })
if (elements.length > 0) {
if (items.length > 4) dispatch('resize', elements[0]?.clientWidth)
else {
allWidth = 0
for (let i = 0; i < items.length; i++) {
if (elements[i].clientWidth !== undefined && allWidth < elements[i].clientWidth) {
allWidth = elements[i].clientWidth
}
}
dispatch('resize', allWidth + (items.length - 1) * 3)
}
}
}) })
</script> </script>
{#if kind === 'list' || kind === 'link'} {#if kind === 'list' || kind === 'link'}
{#if items.length > 4} {#if items.length > 4}
<div <div
bind:this={elements[0]}
class="label-box no-shrink" class="label-box no-shrink"
use:tooltip={{ use:tooltip={{
component: TagsItemPresenter, component: TagsItemPresenter,
@ -70,8 +84,8 @@
<TagsReferencePresenter {items} {kind} /> <TagsReferencePresenter {items} {kind} />
</div> </div>
{:else} {:else}
{#each items as value} {#each items as value, i}
<div class="label-box no-shrink" title={value.title}> <div bind:this={elements[i]} class="label-box no-shrink" title={value.title}>
<TagReferencePresenter attr={undefined} {value} {kind} /> <TagReferencePresenter attr={undefined} {value} {kind} />
</div> </div>
{/each} {/each}

View File

@ -18,7 +18,7 @@
import { RuleApplyResult, getClient, getDocRules } from '@hcengineering/presentation' import { RuleApplyResult, getClient, getDocRules } from '@hcengineering/presentation'
import { Component, Issue, IssueTemplate, Project, TrackerEvents } from '@hcengineering/tracker' import { Component, Issue, IssueTemplate, Project, TrackerEvents } from '@hcengineering/tracker'
import { ButtonKind, ButtonShape, ButtonSize, deviceOptionsStore as deviceInfo } from '@hcengineering/ui' import { ButtonKind, ButtonShape, ButtonSize, deviceOptionsStore as deviceInfo } from '@hcengineering/ui'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher, afterUpdate } from 'svelte'
import { Analytics } from '@hcengineering/analytics' import { Analytics } from '@hcengineering/analytics'
import { activeComponent } from '../../issues' import { activeComponent } from '../../issues'
@ -47,6 +47,8 @@
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let element: HTMLDivElement
const handleComponentIdChanged = async (newComponentId: Ref<Component> | null | undefined) => { const handleComponentIdChanged = async (newComponentId: Ref<Component> | null | undefined) => {
if (!isEditable || newComponentId === undefined || (!Array.isArray(value) && value.component === newComponentId)) { if (!isEditable || newComponentId === undefined || (!Array.isArray(value) && value.component === newComponentId)) {
return return
@ -101,11 +103,13 @@
} }
} }
} }
afterUpdate(() => dispatch('resize', element?.clientWidth))
</script> </script>
{#if kind === 'list'} {#if kind === 'list'}
{#if !Array.isArray(value) && value.component} {#if !Array.isArray(value) && value.component}
<div class={compression ? 'label-wrapper' : 'clear-mins'}> <div bind:this={element} class={compression ? 'label-wrapper' : 'clear-mins'}>
<ComponentSelector <ComponentSelector
{kind} {kind}
{size} {size}
@ -127,6 +131,7 @@
{/if} {/if}
{:else} {:else}
<div <div
bind:this={element}
class="flex flex-wrap clear-mins" class="flex flex-wrap clear-mins"
class:minus-margin={kind === 'list-header'} class:minus-margin={kind === 'list-header'}
class:label-wrapper={compression} class:label-wrapper={compression}

View File

@ -55,4 +55,5 @@
{size} {size}
{kind} {kind}
shouldIgnoreOverdue={ignoreOverDue} shouldIgnoreOverdue={ignoreOverDue}
on:resize
/> />

View File

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
--> -->
<script lang="ts"> <script lang="ts">
import { createEventDispatcher, afterUpdate } from 'svelte'
import { WithLookup } from '@hcengineering/core' import { WithLookup } from '@hcengineering/core'
import { getClient } from '@hcengineering/presentation' import { getClient } from '@hcengineering/presentation'
import type { Issue } from '@hcengineering/tracker' import type { Issue } from '@hcengineering/tracker'
@ -26,13 +27,19 @@
export let disabled: boolean = false export let disabled: boolean = false
export let maxWidth: string | undefined = undefined export let maxWidth: string | undefined = undefined
let element: HTMLSpanElement
const dispatch = createEventDispatcher()
$: presenters = $: presenters =
value !== undefined ? getClient().getHierarchy().findMixinMixins(value, view.mixin.ObjectPresenter) : [] value !== undefined ? getClient().getHierarchy().findMixinMixins(value, view.mixin.ObjectPresenter) : []
afterUpdate(() => dispatch('resize', element?.clientWidth))
</script> </script>
{#if value} {#if value && presenters.length > 0}
<span <span
class="presenter-label select-text p-1" bind:this={element}
class="presenter-label select-text"
class:with-margin={shouldUseMargin} class:with-margin={shouldUseMargin}
class:list={kind === 'list'} class:list={kind === 'list'}
style:max-width={maxWidth} style:max-width={maxWidth}
@ -41,7 +48,7 @@
{#if presenters.length > 0} {#if presenters.length > 0}
<div class="flex-row-center"> <div class="flex-row-center">
{#each presenters as mixinPresenter} {#each presenters as mixinPresenter}
<Component is={mixinPresenter.presenter} props={{ value }} /> <Component is={mixinPresenter.presenter} props={{ value, kind }} />
{/each} {/each}
</div> </div>
{/if} {/if}
@ -50,7 +57,6 @@
<style lang="scss"> <style lang="scss">
.presenter-label { .presenter-label {
overflow: hidden;
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
flex-shrink: 1; flex-shrink: 1;

View File

@ -25,7 +25,7 @@
DatePresenter, DatePresenter,
deviceOptionsStore as deviceInfo deviceOptionsStore as deviceInfo
} from '@hcengineering/ui' } from '@hcengineering/ui'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher, afterUpdate } from 'svelte'
import { activeMilestone } from '../../issues' import { activeMilestone } from '../../issues'
import tracker from '../../plugin' import tracker from '../../plugin'
import MilestoneSelector from './MilestoneSelector.svelte' import MilestoneSelector from './MilestoneSelector.svelte'
@ -51,6 +51,8 @@
const client = getClient() const client = getClient()
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let element: HTMLDivElement
const handleMilestoneIdChanged = async (newMilestoneId: Ref<Milestone> | null | undefined) => { const handleMilestoneIdChanged = async (newMilestoneId: Ref<Milestone> | null | undefined) => {
if (!isEditable || newMilestoneId === undefined || (!Array.isArray(value) && value.milestone === newMilestoneId)) { if (!isEditable || newMilestoneId === undefined || (!Array.isArray(value) && value.milestone === newMilestoneId)) {
return return
@ -86,11 +88,12 @@
$: _space = space ?? (!Array.isArray(value) ? value.space : { $in: Array.from(new Set(value.map((it) => it.space))) }) $: _space = space ?? (!Array.isArray(value) ? value.space : { $in: Array.from(new Set(value.map((it) => it.space))) })
$: twoRows = $deviceInfo.twoRows $: twoRows = $deviceInfo.twoRows
afterUpdate(() => dispatch('resize', element?.clientWidth))
</script> </script>
{#if kind === 'list'} {#if kind === 'list'}
{#if !Array.isArray(value) && value.milestone} {#if !Array.isArray(value) && value.milestone}
<div class={compression ? 'label-wrapper' : 'clear-mins'}> <div bind:this={element} class={compression ? 'label-wrapper' : 'clear-mins'}>
<MilestoneSelector <MilestoneSelector
{kind} {kind}
{size} {size}
@ -112,6 +115,7 @@
{/if} {/if}
{:else} {:else}
<div <div
bind:this={element}
class="flex flex-wrap clear-mins" class="flex flex-wrap clear-mins"
class:minus-margin={kind === 'list-header'} class:minus-margin={kind === 'list-header'}
class:label-wrapper={compression} class:label-wrapper={compression}

View File

@ -60,11 +60,11 @@
> >
<svelte:fragment slot="content"> <svelte:fragment slot="content">
{#if title} {#if title}
<span class="caption-color overflow-label pointer-events-none">{title}</span> <span class="label caption-color overflow-label pointer-events-none">{title}</span>
{:else if value} {:else if value}
<span class="caption-color overflow-label pointer-events-none">{value}</span> <span class="label caption-color overflow-label pointer-events-none">{value}</span>
{:else} {:else}
<span class="content-dark-color pointer-events-none"> <span class="label content-dark-color pointer-events-none">
<Label label={placeholder} /> <Label label={placeholder} />
</span> </span>
{/if} {/if}

View File

@ -41,7 +41,10 @@
} }
function save () { function save () {
filter.value = search ? [search] : [] if (search == null || search === '') {
return
}
filter.value = [search]
onChange(filter) onChange(filter)
dispatch('close') dispatch('close')
@ -61,5 +64,5 @@
on:change on:change
/> />
</div> </div>
<Button shape="filter" label={view.string.Apply} on:click={save} /> <Button shape="filter" label={view.string.Apply} disabled={search === ''} on:click={save} />
</div> </div>

View File

@ -84,6 +84,11 @@
onMount(() => { onMount(() => {
dispatch('on-mount') dispatch('on-mount')
}) })
let minWidth: number | undefined = undefined
const sizes = new Map<number, number>()
const calcSizes = (): void => {
minWidth = sizes.size > 0 ? Array.from(sizes.values()).reduce((a, b) => a + b, 0) : undefined
}
</script> </script>
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->
@ -147,14 +152,19 @@
{/if} {/if}
<GrowPresenter /> <GrowPresenter />
{#if !compactMode} {#if !compactMode}
<div class="compression-bar"> <div class="compression-bar" style:min-width={`${minWidth}px`}>
{#each model.filter((p) => p.displayProps?.compression === true) as attrModel} {#each model.filter((p) => p.displayProps?.compression === true) as attrModel, index}
<ListPresenter <ListPresenter
{docObject} {docObject}
attributeModel={attrModel} attributeModel={attrModel}
props={getProps(props, $restrictionStore.readonly)} props={getProps(props, $restrictionStore.readonly)}
value={getObjectValue(attrModel.key, docObject)} value={getObjectValue(attrModel.key, docObject)}
onChange={getOnChange(docObject, attrModel)} onChange={getOnChange(docObject, attrModel)}
on:resize={(e) => {
if (e.detail == null) return
sizes.set(index, e.detail)
calcSizes()
}}
/> />
{/each} {/each}
</div> </div>

View File

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
--> -->
<script lang="ts"> <script lang="ts">
import { createEventDispatcher } from 'svelte'
import core, { Doc } from '@hcengineering/core' import core, { Doc } from '@hcengineering/core'
import { AttributeModel } from '@hcengineering/view' import { AttributeModel } from '@hcengineering/view'
import { FixedColumn } from '../..' import { FixedColumn } from '../..'
@ -26,6 +27,8 @@
export let hideDivider: boolean = false export let hideDivider: boolean = false
export let compactMode: boolean = false export let compactMode: boolean = false
const dispatch = createEventDispatcher()
$: dp = attributeModel?.displayProps $: dp = attributeModel?.displayProps
function joinProps (attribute: AttributeModel, object: Doc, props: Record<string, any>) { function joinProps (attribute: AttributeModel, object: Doc, props: Record<string, any>) {
@ -35,6 +38,10 @@
} }
return { object, ...clearAttributeProps, space: object.space, ...props } return { object, ...clearAttributeProps, space: object.space, ...props }
} }
const translateSize = (e: CustomEvent): void => {
if (e.detail === undefined) return
dispatch('resize', e.detail)
}
</script> </script>
{#if dp?.dividerBefore === true && !hideDivider} {#if dp?.dividerBefore === true && !hideDivider}
@ -49,6 +56,7 @@
kind={'list'} kind={'list'}
{compactMode} {compactMode}
{...joinProps(attributeModel, docObject, props)} {...joinProps(attributeModel, docObject, props)}
on:resize={translateSize}
/> />
</FixedColumn> </FixedColumn>
{:else} {:else}
@ -59,5 +67,6 @@
kind={'list'} kind={'list'}
{compactMode} {compactMode}
{...joinProps(attributeModel, docObject, props)} {...joinProps(attributeModel, docObject, props)}
on:resize={translateSize}
/> />
{/if} {/if}

View File

@ -1786,6 +1786,9 @@ async function createPersonAccount (
personAccountId personAccountId
) )
} else { } else {
if (roleOrder[existingAccount.role] < roleOrder[role]) {
await ops.update(existingAccount, { role })
}
const person = await ops.findOne(contact.class.Person, { _id: existingAccount.person }) const person = await ops.findOne(contact.class.Person, { _id: existingAccount.person })
if (person === undefined) { if (person === undefined) {
// Employee was deleted, let's restore it. // Employee was deleted, let's restore it.
@ -1794,10 +1797,16 @@ async function createPersonAccount (
await ops.updateDoc(contact.class.PersonAccount, existingAccount.space, existingAccount._id, { await ops.updateDoc(contact.class.PersonAccount, existingAccount.space, existingAccount._id, {
person: employeeId person: employeeId
}) })
} else if (ops.getHierarchy().hasMixin(person, contact.mixin.Employee)) { } else if (shouldCreateEmployee) {
const employee = ops.getHierarchy().as(person, contact.mixin.Employee) if (ops.getHierarchy().hasMixin(person, contact.mixin.Employee)) {
if (!employee.active) { const employee = ops.getHierarchy().as(person, contact.mixin.Employee)
await ops.update(employee, { if (!employee.active) {
await ops.update(employee, {
active: true
})
}
} else {
await ops.createMixin(person._id, contact.class.Person, contact.space.Contacts, contact.mixin.Employee, {
active: true active: true
}) })
} }

View File

@ -71,8 +71,11 @@ export class FullTextIndex implements WithFind {
} }
async close (): Promise<void> { async close (): Promise<void> {
this.indexer.triggerIndexing()
if (!this.upgrade) { if (!this.upgrade) {
await this.indexer.cancel() await this.indexer.cancel()
} else {
await this.indexer.processUpload(this.indexer.metrics)
} }
} }

View File

@ -351,7 +351,9 @@ class TSessionManager implements SessionManager {
version: this.modelVersion, version: this.modelVersion,
workspaceVersion: versionToString(workspaceInfo.version), workspaceVersion: versionToString(workspaceInfo.version),
workspace: workspaceInfo.workspaceId, workspace: workspaceInfo.workspaceId,
workspaceUrl: workspaceInfo.workspaceUrl workspaceUrl: workspaceInfo.workspaceUrl,
email: token.email,
extra: JSON.stringify(token.extra ?? {})
}) })
// Version mismatch, return upgrading. // Version mismatch, return upgrading.
return { upgrade: true, upgradeInfo: workspaceInfo.upgrade } return { upgrade: true, upgradeInfo: workspaceInfo.upgrade }

View File

@ -14,9 +14,7 @@
// //
import core, { import core, {
BackupClient,
Branding, Branding,
Client as CoreClient,
coreId, coreId,
DOMAIN_BENCHMARK, DOMAIN_BENCHMARK,
DOMAIN_MIGRATION, DOMAIN_MIGRATION,
@ -34,13 +32,13 @@ import core, {
TxOperations, TxOperations,
WorkspaceId, WorkspaceId,
WorkspaceIdWithUrl, WorkspaceIdWithUrl,
type Client,
type Doc, type Doc,
type Ref, type Ref,
type WithLookup type WithLookup
} from '@hcengineering/core' } from '@hcengineering/core'
import { consoleModelLogger, MigrateOperation, ModelLogger, tryMigrate } from '@hcengineering/model' import { consoleModelLogger, MigrateOperation, ModelLogger, tryMigrate } from '@hcengineering/model'
import { DomainIndexHelperImpl, Pipeline, StorageAdapter, type DbAdapter } from '@hcengineering/server-core' import { DomainIndexHelperImpl, Pipeline, StorageAdapter, type DbAdapter } from '@hcengineering/server-core'
import { connect } from './connect'
import { InitScript, WorkspaceInitializer } from './initializer' import { InitScript, WorkspaceInitializer } from './initializer'
import toolPlugin from './plugin' import toolPlugin from './plugin'
import { MigrateClientImpl } from './upgrade' import { MigrateClientImpl } from './upgrade'
@ -165,23 +163,15 @@ export async function updateModel (
try { try {
let i = 0 let i = 0
for (const op of migrateOperations) { for (const op of migrateOperations) {
logger.log('Migrate', { name: op[0] }) const st = Date.now()
await op[1].upgrade(migrateState, async () => connection as any, logger) await op[1].upgrade(migrateState, async () => connection as any, logger)
const tdelta = Date.now() - st
if (tdelta > 0) {
logger.log('Create', { name: op[0], time: tdelta })
}
i++ i++
await progress((((100 / migrateOperations.length) * i) / 100) * 30) await progress((((100 / migrateOperations.length) * i) / 100) * 100)
} }
// Create update indexes
await createUpdateIndexes(
ctx,
connection.getHierarchy(),
connection.getModel(),
pipeline,
async (value) => {
await progress(30 + (Math.min(value, 100) / 100) * 70)
},
workspaceId
)
await progress(100) await progress(100)
} catch (e: any) { } catch (e: any) {
logger.error('error', { error: e }) logger.error('error', { error: e })
@ -203,6 +193,7 @@ export async function initializeWorkspace (
): Promise<void> { ): Promise<void> {
const initWS = branding?.initWorkspace ?? getMetadata(toolPlugin.metadata.InitWorkspace) const initWS = branding?.initWorkspace ?? getMetadata(toolPlugin.metadata.InitWorkspace)
const scriptUrl = getMetadata(toolPlugin.metadata.InitScriptURL) const scriptUrl = getMetadata(toolPlugin.metadata.InitScriptURL)
ctx.info('Init script details', { scriptUrl, initWS })
if (initWS === undefined || scriptUrl === undefined) return if (initWS === undefined || scriptUrl === undefined) return
try { try {
// `https://raw.githubusercontent.com/hcengineering/init/main/script.yaml` // `https://raw.githubusercontent.com/hcengineering/init/main/script.yaml`
@ -237,11 +228,12 @@ export async function upgradeModel (
workspaceId: WorkspaceIdWithUrl, workspaceId: WorkspaceIdWithUrl,
txes: Tx[], txes: Tx[],
pipeline: Pipeline, pipeline: Pipeline,
connection: Client,
storageAdapter: StorageAdapter, storageAdapter: StorageAdapter,
migrateOperations: [string, MigrateOperation][], migrateOperations: [string, MigrateOperation][],
logger: ModelLogger = consoleModelLogger, logger: ModelLogger = consoleModelLogger,
progress: (value: number) => Promise<void>, progress: (value: number) => Promise<void>,
forceIndexes: boolean = false updateIndexes: 'perform' | 'skip' | 'disable' = 'skip'
): Promise<Tx[]> { ): Promise<Tx[]> {
if (txes.some((tx) => tx.objectSpace !== core.space.Model)) { if (txes.some((tx) => tx.objectSpace !== core.space.Model)) {
throw Error('Model txes must target only core.space.Model') throw Error('Model txes must target only core.space.Model')
@ -308,87 +300,69 @@ export async function upgradeModel (
workspaceId workspaceId
) )
} }
if (forceIndexes) { if (updateIndexes === 'perform') {
await upgradeIndexes() await upgradeIndexes()
} }
await ctx.with('migrate', {}, async (ctx) => { await ctx.with('migrate', {}, async (ctx) => {
let i = 0 let i = 0
for (const op of migrateOperations) { for (const op of migrateOperations) {
const t = Date.now()
try { try {
const t = Date.now()
await ctx.with(op[0], {}, async () => { await ctx.with(op[0], {}, async () => {
await op[1].migrate(migrateClient, logger) await op[1].migrate(migrateClient, logger)
}) })
const tdelta = Date.now() - t
if (tdelta > 0) {
logger.log('migrate:', { workspaceId: workspaceId.name, operation: op[0], time: Date.now() - t })
}
} catch (err: any) { } catch (err: any) {
logger.error(`error during migrate: ${op[0]} ${err.message}`, err) logger.error(`error during migrate: ${op[0]} ${err.message}`, err)
throw err throw err
} }
logger.log('migrate:', { workspaceId: workspaceId.name, operation: op[0], time: Date.now() - t })
await progress(20 + ((100 / migrateOperations.length) * i * 20) / 100) await progress(20 + ((100 / migrateOperations.length) * i * 20) / 100)
i++ i++
} }
await tryMigrate(migrateClient, coreId, [ if (updateIndexes === 'skip') {
{ await tryMigrate(migrateClient, coreId, [
state: 'indexes-v5', {
func: upgradeIndexes state: 'indexes-v5',
} func: upgradeIndexes
]) }
])
}
}) })
logger.log('Apply upgrade operations', { workspaceId: workspaceId.name }) logger.log('Apply upgrade operations', { workspaceId: workspaceId.name })
let connection: (CoreClient & BackupClient) | undefined await ctx.with('upgrade', {}, async (ctx) => {
const getUpgradeClient = async (): Promise<CoreClient & BackupClient> => let i = 0
await ctx.with('connect-platform', {}, async (ctx) => { for (const op of migrateOperations) {
if (connection !== undefined) { const t = Date.now()
return connection await ctx.with(op[0], {}, () => op[1].upgrade(migrateState, async () => connection, logger))
} const tdelta = Date.now() - t
connection = (await connect( if (tdelta > 0) {
transactorUrl, logger.log('upgrade:', { operation: op[0], time: tdelta, workspaceId: workspaceId.name })
workspaceId,
undefined,
{
mode: 'backup',
model: 'upgrade',
admin: 'true'
},
model
)) as CoreClient & BackupClient
return connection
})
try {
await ctx.with('upgrade', {}, async (ctx) => {
let i = 0
for (const op of migrateOperations) {
const t = Date.now()
await ctx.with(op[0], {}, () => op[1].upgrade(migrateState, getUpgradeClient, logger))
logger.log('upgrade:', { operation: op[0], time: Date.now() - t, workspaceId: workspaceId.name })
await progress(60 + ((100 / migrateOperations.length) * i * 30) / 100)
i++
}
})
if (connection === undefined) {
// We need to send reboot for workspace
ctx.info('send force close', { workspace: workspaceId.name, transactorUrl })
const serverEndpoint = transactorUrl.replaceAll('wss://', 'https://').replace('ws://', 'http://')
const token = generateToken(systemAccountEmail, workspaceId, { admin: 'true' })
try {
await fetch(
serverEndpoint + `/api/v1/manage?token=${token}&operation=force-close&wsId=${toWorkspaceString(workspaceId)}`,
{
method: 'PUT'
}
)
} catch (err: any) {
// Ignore error if transactor is not yet ready
} }
await progress(60 + ((100 / migrateOperations.length) * i * 30) / 100)
i++
} }
} finally { })
await connection?.sendForceClose()
await connection?.close() // We need to send reboot for workspace
ctx.info('send force close', { workspace: workspaceId.name, transactorUrl })
const serverEndpoint = transactorUrl.replaceAll('wss://', 'https://').replace('ws://', 'http://')
const token = generateToken(systemAccountEmail, workspaceId, { admin: 'true' })
try {
await fetch(
serverEndpoint + `/api/v1/manage?token=${token}&operation=force-close&wsId=${toWorkspaceString(workspaceId)}`,
{
method: 'PUT'
}
)
} catch (err: any) {
// Ignore error if transactor is not yet ready
} }
return model return model
} }
@ -407,7 +381,13 @@ async function prepareMigrationClient (
const migrateClient = new MigrateClientImpl(pipeline, hierarchy, model, logger, storageAdapter, workspaceId) const migrateClient = new MigrateClientImpl(pipeline, hierarchy, model, logger, storageAdapter, workspaceId)
const states = await migrateClient.find<MigrationState>(DOMAIN_MIGRATION, { _class: core.class.MigrationState }) const states = await migrateClient.find<MigrationState>(DOMAIN_MIGRATION, { _class: core.class.MigrationState })
const sts = Array.from(groupByArray(states, (it) => it.plugin).entries()) const sts = Array.from(groupByArray(states, (it) => it.plugin).entries())
const migrateState = new Map(sts.map((it) => [it[0], new Set(it[1].map((q) => q.state))]))
const _toSet = (vals: WithLookup<MigrationState>[]): Set<string> => {
return new Set(vals.map((q) => q.state))
}
const migrateState = new Map<string, Set<string>>(sts.map((it) => [it[0], _toSet(it[1])]))
// const migrateState = new Map(sts.map((it) => [it[0], new Set(it[1].map((q) => q.state))]))
migrateClient.migrateState = migrateState migrateClient.migrateState = migrateState
return { migrateClient, migrateState } return { migrateClient, migrateState }

View File

@ -90,6 +90,8 @@ export function serveWorkspaceAccount (
setMetadata(serverNotification.metadata.InboxOnlyNotifications, true) setMetadata(serverNotification.metadata.InboxOnlyNotifications, true)
let canceled = false
const worker = new WorkspaceWorker( const worker = new WorkspaceWorker(
version, version,
txes, txes,
@ -100,17 +102,22 @@ export function serveWorkspaceAccount (
brandings brandings
) )
void worker.start(measureCtx, { void worker.start(
errorHandler: async (ws, err) => { measureCtx,
Analytics.handleError(err) {
errorHandler: async (ws, err) => {
Analytics.handleError(err)
},
force: false,
console: false,
logs: 'upgrade-logs',
waitTimeout
}, },
force: false, () => canceled
console: false, )
logs: 'upgrade-logs',
waitTimeout
})
const close = (): void => { const close = (): void => {
canceled = true
onClose?.() onClose?.()
} }

View File

@ -79,7 +79,7 @@ export class WorkspaceWorker {
wakeup: () => void = () => {} wakeup: () => void = () => {}
defaultWakeup: () => void = () => {} defaultWakeup: () => void = () => {}
async start (ctx: MeasureContext, opt: WorkspaceOptions): Promise<void> { async start (ctx: MeasureContext, opt: WorkspaceOptions, isCanceled: () => boolean): Promise<void> {
this.defaultWakeup = () => { this.defaultWakeup = () => {
ctx.info("I'm busy", { version: this.version, region: this.region }) ctx.info("I'm busy", { version: this.version, region: this.region })
} }
@ -92,7 +92,7 @@ export class WorkspaceWorker {
ctx.info('Successfully connected to the account service') ctx.info('Successfully connected to the account service')
while (true) { while (!isCanceled()) {
await this.waitForAvailableThread() await this.waitForAvailableThread()
const workspace = await ctx.with('get-pending-workspace', {}, async (ctx) => { const workspace = await ctx.with('get-pending-workspace', {}, async (ctx) => {

View File

@ -131,23 +131,20 @@ export async function createWorkspace (
usePassedCtx: true usePassedCtx: true
}) })
const txAdapter = await txFactory(ctx, hierarchy, dbUrl, wsId, modelDb, storageAdapter) const txAdapter = await txFactory(ctx, hierarchy, dbUrl, wsId, modelDb, storageAdapter)
await childLogger.withLog('init-workspace', {}, async (ctx) => { await childLogger.withLog('init-workspace', {}, async (ctx) => {
await initModel(ctx, wsId, txes, txAdapter, storageAdapter, ctxModellogger, async (value) => { await initModel(ctx, wsId, txes, txAdapter, storageAdapter, ctxModellogger, async (value) => {})
await handleWsEvent?.('progress', version, 10 + Math.round((Math.min(value, 100) / 100) * 10))
})
}) })
const client = new TxOperations(wrapPipeline(ctx, pipeline, wsUrl), core.account.ConfigUser) const client = new TxOperations(wrapPipeline(ctx, pipeline, wsUrl), core.account.ConfigUser)
await updateModel(ctx, wsId, migrationOperation, client, pipeline, ctxModellogger, async (value) => { await updateModel(ctx, wsId, migrationOperation, client, pipeline, ctxModellogger, async (value) => {
await handleWsEvent?.('progress', version, 20 + Math.round((Math.min(value, 100) / 100) * 10)) await handleWsEvent?.('progress', version, 10 + Math.round((Math.min(value, 100) / 100) * 10))
}) })
ctx.info('Starting init script if any') ctx.info('Starting init script if any')
await initializeWorkspace(ctx, branding, wsUrl, storageAdapter, client, ctxModellogger, async (value) => { await initializeWorkspace(ctx, branding, wsUrl, storageAdapter, client, ctxModellogger, async (value) => {
ctx.info('Init script progress', { value }) ctx.info('Init script progress', { value })
await handleWsEvent?.('progress', version, 30 + Math.round((Math.min(value, 100) / 100) * 60)) await handleWsEvent?.('progress', version, 20 + Math.round((Math.min(value, 100) / 100) * 60))
}) })
await upgradeWorkspaceWith( await upgradeWorkspaceWith(
@ -157,14 +154,15 @@ export async function createWorkspace (
migrationOperation, migrationOperation,
workspaceInfo, workspaceInfo,
pipeline, pipeline,
client,
storageAdapter, storageAdapter,
ctxModellogger, ctxModellogger,
async (event, version, value) => { async (event, version, value) => {
ctx.info('Init script progress', { event, value }) ctx.info('Init script progress', { event, value })
await handleWsEvent?.('progress', version, 90 + Math.round((Math.min(value, 100) / 100) * 10)) await handleWsEvent?.('progress', version, 80 + Math.round((Math.min(value, 100) / 100) * 20))
}, },
false, false,
false 'disable'
) )
await handleWsEvent?.('create-done', version, 100, '') await handleWsEvent?.('create-done', version, 100, '')
@ -216,6 +214,12 @@ export async function upgradeWorkspace (
return return
} }
const wsUrl: WorkspaceIdWithUrl = {
name: ws.workspace,
workspaceName: ws.workspaceName ?? '',
workspaceUrl: ws.workspaceUrl ?? ''
}
await upgradeWorkspaceWith( await upgradeWorkspaceWith(
ctx, ctx,
version, version,
@ -223,11 +227,12 @@ export async function upgradeWorkspace (
migrationOperation, migrationOperation,
ws, ws,
pipeline, pipeline,
wrapPipeline(ctx, pipeline, wsUrl),
storageAdapter, storageAdapter,
logger, logger,
handleWsEvent, handleWsEvent,
forceUpdate, forceUpdate,
forceIndexes, forceIndexes ? 'perform' : 'skip',
external external
) )
} finally { } finally {
@ -246,6 +251,7 @@ export async function upgradeWorkspaceWith (
migrationOperation: [string, MigrateOperation][], migrationOperation: [string, MigrateOperation][],
ws: BaseWorkspaceInfo, ws: BaseWorkspaceInfo,
pipeline: Pipeline, pipeline: Pipeline,
connection: Client,
storageAdapter: StorageAdapter, storageAdapter: StorageAdapter,
logger: ModelLogger = consoleModelLogger, logger: ModelLogger = consoleModelLogger,
handleWsEvent?: ( handleWsEvent?: (
@ -255,7 +261,7 @@ export async function upgradeWorkspaceWith (
message?: string message?: string
) => Promise<void>, ) => Promise<void>,
forceUpdate: boolean = true, forceUpdate: boolean = true,
forceIndexes: boolean = false, updateIndexes: 'perform' | 'skip' | 'disable' = 'skip',
external: boolean = false external: boolean = false
): Promise<void> { ): Promise<void> {
const versionStr = versionToString(version) const versionStr = versionToString(version)
@ -310,13 +316,14 @@ export async function upgradeWorkspaceWith (
wsId, wsId,
txes, txes,
pipeline, pipeline,
connection,
storageAdapter, storageAdapter,
migrationOperation, migrationOperation,
logger, logger,
async (value) => { async (value) => {
progress = value progress = value
}, },
forceIndexes updateIndexes
) )
await handleWsEvent?.('upgrade-done', version, 100, '') await handleWsEvent?.('upgrade-done', version, 100, '')

View File

@ -2,11 +2,13 @@
import { Issue } from '@hcengineering/tracker' import { Issue } from '@hcengineering/tracker'
import { getClient } from '@hcengineering/presentation' import { getClient } from '@hcengineering/presentation'
import type { ButtonKind } from '@hcengineering/ui'
import { HyperlinkEditor } from '@hcengineering/view-resources' import { HyperlinkEditor } from '@hcengineering/view-resources'
import github from '../../plugin' import github from '../../plugin'
import { integrationRepositories } from '../utils' import { integrationRepositories } from '../utils'
export let value: Issue export let value: Issue
export let kind: ButtonKind = 'ghost'
$: ghIssue = getClient().getHierarchy().asIf(value, github.mixin.GithubIssue) $: ghIssue = getClient().getHierarchy().asIf(value, github.mixin.GithubIssue)
@ -14,14 +16,12 @@
</script> </script>
{#if ghIssue !== undefined && ghIssue.url !== '' && repository !== undefined} {#if ghIssue !== undefined && ghIssue.url !== '' && repository !== undefined}
<div class="flex flex-row-center"> <HyperlinkEditor
<HyperlinkEditor readonly
readonly icon={github.icon.Github}
icon={github.icon.Github} {kind}
kind={'ghost'} value={ghIssue.url}
value={ghIssue.url} placeholder={github.string.Issue}
placeholder={github.string.Issue} title={`${repository.name}`}
title={`${repository.name}`} />
/>
</div>
{/if} {/if}

View File

@ -271,7 +271,6 @@ async function processMigrateMarkupFor (
client: MigrationClient, client: MigrationClient,
iterator: MigrationIterator<DocSyncInfo> iterator: MigrationIterator<DocSyncInfo>
): Promise<void> { ): Promise<void> {
let processed = 0
while (true) { while (true) {
const docs = await iterator.next(1000) const docs = await iterator.next(1000)
if (docs === null || docs.length === 0) { if (docs === null || docs.length === 0) {
@ -298,9 +297,6 @@ async function processMigrateMarkupFor (
if (operations.length > 0) { if (operations.length > 0) {
await client.bulk(DOMAIN_GITHUB, operations) await client.bulk(DOMAIN_GITHUB, operations)
} }
processed += docs.length
console.log('...processed', processed)
} }
} }

View File

@ -162,10 +162,15 @@ export class PlatformWorker {
errors = true errors = true
} }
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
this.triggerCheckWorkspaces = resolve this.triggerCheckWorkspaces = () => {
this.ctx.info('Workspaces check triggered') this.ctx.info('Workspaces check triggered')
this.triggerCheckWorkspaces = () => {}
resolve()
}
if (errors) { if (errors) {
setTimeout(resolve, 5000) setTimeout(() => {
this.triggerCheckWorkspaces()
}, 5000)
} }
}) })
} }
@ -650,6 +655,9 @@ export class PlatformWorker {
} }
private async checkWorkspaces (): Promise<boolean> { private async checkWorkspaces (): Promise<boolean> {
this.ctx.info('************************* Check workspaces ************************* ', {
workspaces: this.clients.size
})
let workspaces = await this.getWorkspaces() let workspaces = await this.getWorkspaces()
if (process.env.GITHUB_USE_WS !== undefined) { if (process.env.GITHUB_USE_WS !== undefined) {
workspaces = [process.env.GITHUB_USE_WS] workspaces = [process.env.GITHUB_USE_WS]
@ -660,7 +668,14 @@ export class PlatformWorker {
let errors = 0 let errors = 0
let idx = 0 let idx = 0
const connecting = new Map<string, number>() const connecting = new Map<string, number>()
const st = Date.now()
const connectingInfo = setInterval(() => { const connectingInfo = setInterval(() => {
this.ctx.info('****** connecting to workspaces ******', {
connecting: connecting.size,
time: Date.now() - st,
workspaces: workspaces.length,
queue: rateLimiter.processingQueue.size
})
for (const [c, d] of connecting.entries()) { for (const [c, d] of connecting.entries()) {
this.ctx.info('connecting to workspace', { workspace: c, time: Date.now() - d }) this.ctx.info('connecting to workspace', { workspace: c, time: Date.now() - d })
} }
@ -727,7 +742,7 @@ export class PlatformWorker {
} }
) )
if (worker !== undefined) { if (worker !== undefined) {
workerCtx.info('Register worker Done', { workerCtx.info('************************* Register worker Done ************************* ', {
workspaceId: workspaceInfo.workspaceId, workspaceId: workspaceInfo.workspaceId,
workspace: workspaceInfo.workspace, workspace: workspaceInfo.workspace,
index: widx, index: widx,
@ -736,12 +751,15 @@ export class PlatformWorker {
// No if no integration, we will try connect one more time in a time period // No if no integration, we will try connect one more time in a time period
this.clients.set(workspace, worker) this.clients.set(workspace, worker)
} else { } else {
workerCtx.info('Failed Register worker, timeout or integrations removed', { workerCtx.info(
workspaceId: workspaceInfo.workspaceId, '************************* Failed Register worker, timeout or integrations removed *************************',
workspace: workspaceInfo.workspace, {
index: widx, workspaceId: workspaceInfo.workspaceId,
total: workspaces.length workspace: workspaceInfo.workspace,
}) index: widx,
total: workspaces.length
}
)
errors++ errors++
} }
} catch (e: any) { } catch (e: any) {
@ -754,6 +772,10 @@ export class PlatformWorker {
} }
}) })
} }
this.ctx.info('************************* Waiting To complete Workspace processing ************************* ', {
workspaces: this.clients.size,
rateLimiter: rateLimiter.processingQueue.size
})
try { try {
await rateLimiter.waitProcessing() await rateLimiter.waitProcessing()
} catch (e: any) { } catch (e: any) {
@ -761,6 +783,11 @@ export class PlatformWorker {
errors++ errors++
} }
clearInterval(connectingInfo) clearInterval(connectingInfo)
this.ctx.info('************************* Check close deleted ************************* ', {
workspaces: this.clients.size,
deleted: toDelete.size
})
// Close deleted workspaces // Close deleted workspaces
for (const deleted of Array.from(toDelete.keys())) { for (const deleted of Array.from(toDelete.keys())) {
const ws = this.clients.get(deleted) const ws = this.clients.get(deleted)
@ -768,7 +795,7 @@ export class PlatformWorker {
try { try {
this.ctx.info('workspace removed from tracking list', { workspace: deleted }) this.ctx.info('workspace removed from tracking list', { workspace: deleted })
this.clients.delete(deleted) this.clients.delete(deleted)
await ws.close() void ws.close()
} catch (err: any) { } catch (err: any) {
Analytics.handleError(err) Analytics.handleError(err)
errors++ errors++

View File

@ -127,8 +127,9 @@ export class GithubWorker implements IntegrationManager {
this.closing = true this.closing = true
this.ctx.warn('Closing', { workspace: this.workspace.name }) this.ctx.warn('Closing', { workspace: this.workspace.name })
this.triggerSync() this.triggerSync()
await this.syncPromise await Promise.all([await this.syncPromise, new Promise<void>((resolve) => setTimeout(resolve, 5000))])
this.ctx.warn('ClosingDone', { workspace: this.workspace.name })
this.ctx.warn('Closing Done', { workspace: this.workspace.name })
await this.client.close() await this.client.close()
} }

View File

@ -3,12 +3,10 @@ CREATE SCHEMA IF NOT EXISTS blob;
DROP TABLE IF EXISTS blob.blob; DROP TABLE IF EXISTS blob.blob;
DROP TABLE IF EXISTS blob.data; DROP TABLE IF EXISTS blob.data;
DROP TYPE IF EXISTS blob.content_type;
DROP TYPE IF EXISTS blob.location; DROP TYPE IF EXISTS blob.location;
-- B L O B -- B L O B
CREATE TYPE blob.content_type AS ENUM ('application','audio','font','image','model','text','video');
CREATE TYPE blob.location AS ENUM ('kv', 'weur', 'eeur', 'wnam', 'enam', 'apac'); CREATE TYPE blob.location AS ENUM ('kv', 'weur', 'eeur', 'wnam', 'enam', 'apac');
\echo "Creating blob.data..." \echo "Creating blob.data..."
@ -17,8 +15,7 @@ CREATE TABLE blob.data (
location blob.location NOT NULL, location blob.location NOT NULL,
size INT8 NOT NULL, size INT8 NOT NULL,
filename UUID NOT NULL, filename UUID NOT NULL,
type blob.content_type NOT NULL, type STRING(255) NOT NULL,
subtype STRING(64) NOT NULL,
CONSTRAINT pk_data PRIMARY KEY (hash, location) CONSTRAINT pk_data PRIMARY KEY (hash, location)
); );

View File

@ -163,7 +163,6 @@ async function saveBlob (
const { location, bucket } = selectStorage(env, workspace) const { location, bucket } = selectStorage(env, workspace)
const size = file.size const size = file.size
const [mimetype, subtype] = type.split('/')
const httpMetadata = { contentType: type, cacheControl } const httpMetadata = { contentType: type, cacheControl }
const filename = getUniqueFilename() const filename = getUniqueFilename()
@ -179,7 +178,7 @@ async function saveBlob (
} else { } else {
await bucket.put(filename, file, { httpMetadata }) await bucket.put(filename, file, { httpMetadata })
await sql.begin((sql) => [ await sql.begin((sql) => [
db.createData(sql, { hash, location, filename, type: mimetype, subtype, size }), db.createData(sql, { hash, location, filename, type, size }),
db.createBlob(sql, { workspace, name, hash, location }) db.createBlob(sql, { workspace, name, hash, location })
]) ])
} }
@ -201,7 +200,7 @@ async function saveBlob (
} else { } else {
// Otherwise register a new hash and blob // Otherwise register a new hash and blob
await sql.begin((sql) => [ await sql.begin((sql) => [
db.createData(sql, { hash, location, filename, type: mimetype, subtype, size }), db.createData(sql, { hash, location, filename, type, size }),
db.createBlob(sql, { workspace, name, hash, location }) db.createBlob(sql, { workspace, name, hash, location })
]) ])
} }
@ -227,9 +226,8 @@ export async function handleBlobUploaded (env: Env, workspace: string, name: str
} else { } else {
const size = object.size const size = object.size
const type = object.httpMetadata.contentType ?? 'application/octet-stream' const type = object.httpMetadata.contentType ?? 'application/octet-stream'
const [mimetype, subtype] = type.split('/')
await db.createData(sql, { hash, location, filename, type: mimetype, subtype, size }) await db.createData(sql, { hash, location, filename, type, size })
await db.createBlob(sql, { workspace, name, hash, location }) await db.createBlob(sql, { workspace, name, hash, location })
} }
} }

View File

@ -25,7 +25,6 @@ export interface BlobDataRecord extends BlobDataId {
filename: UUID filename: UUID
size: number size: number
type: string type: string
subtype: string
} }
export interface BlobId { export interface BlobId {
@ -47,7 +46,7 @@ export async function getData (sql: postgres.Sql, dataId: BlobDataId): Promise<B
const { hash, location } = dataId const { hash, location } = dataId
const rows = await sql<BlobDataRecord[]>` const rows = await sql<BlobDataRecord[]>`
SELECT hash, location, filename, size, type, subtype SELECT hash, location, filename, size, type
FROM blob.data FROM blob.data
WHERE hash = ${hash} AND location = ${location} WHERE hash = ${hash} AND location = ${location}
` `
@ -60,11 +59,11 @@ export async function getData (sql: postgres.Sql, dataId: BlobDataId): Promise<B
} }
export async function createData (sql: postgres.Sql, data: BlobDataRecord): Promise<void> { export async function createData (sql: postgres.Sql, data: BlobDataRecord): Promise<void> {
const { hash, location, filename, size, type, subtype } = data const { hash, location, filename, size, type } = data
await sql` await sql`
UPSERT INTO blob.data (hash, location, filename, size, type, subtype) UPSERT INTO blob.data (hash, location, filename, size, type)
VALUES (${hash}, ${location}, ${filename}, ${size}, ${type}, ${subtype}) VALUES (${hash}, ${location}, ${filename}, ${size}, ${type})
` `
} }