Skip to content

Commit

Permalink
UBERF-7510: add logging and catch errors on cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
  • Loading branch information
haiodo committed Jul 4, 2024
1 parent 630ae21 commit 7a4c1e4
Show file tree
Hide file tree
Showing 30 changed files with 86 additions and 647 deletions.
6 changes: 0 additions & 6 deletions models/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
DOMAIN_BLOB,
DOMAIN_CONFIGURATION,
DOMAIN_DOC_INDEX_STATE,
DOMAIN_FULLTEXT_BLOB,
DOMAIN_MIGRATION,
DOMAIN_MODEL,
IndexKind,
Expand All @@ -38,7 +37,6 @@ import {
type Enum,
type EnumOf,
type FieldIndex,
type FullTextData,
type FullTextSearchContext,
type IndexStageState,
type IndexingConfiguration,
Expand Down Expand Up @@ -309,10 +307,6 @@ export class TPluginConfiguration extends TDoc implements PluginConfiguration {
enabled!: boolean
beta!: boolean
}
@Model(core.class.FulltextData, core.class.Doc, DOMAIN_FULLTEXT_BLOB)
export class TFulltextData extends TDoc implements FullTextData {
data!: any
}

@Model(core.class.DocIndexState, core.class.Doc, DOMAIN_DOC_INDEX_STATE)
export class TDocIndexState extends TDoc implements DocIndexState {
Expand Down
2 changes: 0 additions & 2 deletions models/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import {
TEnum,
TEnumOf,
TFullTextSearchContext,
TFulltextData,
TIndexConfiguration,
TIndexStageState,
TInterface,
Expand Down Expand Up @@ -164,7 +163,6 @@ export function createModel (builder: Builder): void {
TUserStatus,
TEnum,
TTypeAny,
TFulltextData,
TTypeRelatedDocument,
TDocIndexState,
TIndexStageState,
Expand Down
16 changes: 1 addition & 15 deletions models/server-attachment/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@

import { type Builder } from '@hcengineering/model'

import attachment from '@hcengineering/attachment'
import core from '@hcengineering/core'
import serverAttachment from '@hcengineering/server-attachment'
import serverCore from '@hcengineering/server-core'

export { serverAttachmentId } from '@hcengineering/server-attachment'

export function createModel (builder: Builder): void {
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverAttachment.trigger.OnAttachmentDelete,
txMatch: {
_class: core.class.TxCollectionCUD,
'tx.objectClass': attachment.class.Attachment,
'tx._class': core.class.TxRemoveDoc
}
})
}
export function createModel (builder: Builder): void {}
14 changes: 0 additions & 14 deletions packages/core/src/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,6 @@ export const DOMAIN_TRANSIENT = 'transient' as Domain
*/
export const DOMAIN_BLOB = 'blob' as Domain

/**
* Special domain to access s3 blob data.
* @public
*/
export const DOMAIN_FULLTEXT_BLOB = 'fulltext-blob' as Domain

/**
* Special domain to access s3 blob data.
* @public
Expand Down Expand Up @@ -494,14 +488,6 @@ export function versionToString (version: Version | Data<Version>): string {
return `${version?.major}.${version?.minor}.${version?.patch}`
}

/**
* Blob data from s3 storage
* @public
*/
export interface FullTextData extends Doc {
data: any
}

/**
* @public
*
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import type {
DomainIndexConfiguration,
Enum,
EnumOf,
FullTextData,
FullTextSearchContext,
Hyperlink,
IndexStageState,
Expand Down Expand Up @@ -134,7 +133,6 @@ export default plugin(coreId, {
Version: '' as Ref<Class<Version>>,
PluginConfiguration: '' as Ref<Class<PluginConfiguration>>,
UserStatus: '' as Ref<Class<UserStatus>>,
FulltextData: '' as Ref<Class<FullTextData>>,
TypeRelatedDocument: '' as Ref<Class<Type<RelatedDocument>>>,
DocIndexState: '' as Ref<Class<DocIndexState>>,
IndexStageState: '' as Ref<Class<IndexStageState>>,
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
DocIndexState,
DOMAIN_BLOB,
DOMAIN_DOC_INDEX_STATE,
DOMAIN_FULLTEXT_BLOB,
DOMAIN_MODEL,
DOMAIN_TRANSIENT,
FullTextSearchContext,
Expand Down Expand Up @@ -713,7 +712,6 @@ export function isClassIndexable (hierarchy: Hierarchy, c: Ref<Class<Doc>>): boo
domain === DOMAIN_TX ||
domain === DOMAIN_MODEL ||
domain === DOMAIN_BLOB ||
domain === DOMAIN_FULLTEXT_BLOB ||
domain === DOMAIN_TRANSIENT
) {
hierarchy.setClassifierProp(c, 'class_indexed', false)
Expand Down
21 changes: 1 addition & 20 deletions packages/presentation/src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
//

import { concatLink, type Blob, type Ref } from '@hcengineering/core'
import { type Blob, type Ref } from '@hcengineering/core'
import { PlatformError, Severity, Status, getMetadata, getResource } from '@hcengineering/platform'
import { type PopupAlignment } from '@hcengineering/ui'
import { writable } from 'svelte/store'
Expand Down Expand Up @@ -54,25 +54,6 @@ export async function uploadFile (file: File): Promise<Ref<Blob>> {
return (await resp.text()) as Ref<Blob>
}

/**
* @public
*/
export async function deleteFile (id: string): Promise<void> {
const uploadUrl = getMetadata(plugin.metadata.UploadURL) ?? ''

const url = concatLink(uploadUrl, `?file=${id}`)
const resp = await fetch(url, {
method: 'DELETE',
headers: {
Authorization: 'Bearer ' + (getMetadata(plugin.metadata.Token) as string)
}
})

if (resp.status !== 200) {
throw new Error('Failed to delete file')
}
}

/**
* @public
*/
Expand Down
5 changes: 2 additions & 3 deletions packages/query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1276,9 +1276,8 @@ export class LiveQuery implements WithTx, Client {
for (const tx of txes) {
if (tx._class === core.class.TxWorkspaceEvent) {
const evt = tx as TxWorkspaceEvent
console.info('checking workspace event', evt._id, evt.params)
await this.checkUpdateEvents(tx as TxWorkspaceEvent)
await this.changePrivateHandler(tx as TxWorkspaceEvent)
await this.checkUpdateEvents(evt)
await this.changePrivateHandler(evt)
}
result.push(await this._tx(tx, docCache))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import {
DraftController,
createQuery,
deleteFile,
draftsStore,
getClient,
getFileMetadata,
Expand Down Expand Up @@ -228,8 +227,6 @@
attachment.attachedToClass,
'attachments'
)
} else {
await deleteFile(attachment.file)
}
}
Expand All @@ -249,14 +246,6 @@
export function removeDraft (removeFiles: boolean): void {
draftController.remove()
if (removeFiles) {
newAttachments.forEach((p) => {
const attachment = attachments.get(p)
if (attachment !== undefined) {
void deleteFile(attachment.file)
}
})
}
}
export function createAttachments (): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import {
createQuery,
DraftController,
deleteFile,
draftsStore,
getClient,
getFileMetadata,
Expand Down Expand Up @@ -243,8 +242,6 @@
'attachments'
)
dispatch('detached', attachment._id)
} else {
await deleteFile(attachment.file)
}
}
Expand All @@ -263,14 +260,6 @@
if (draftKey) {
DraftController.remove(draftKey)
}
if (removeFiles) {
newAttachments.forEach((p) => {
const attachment = attachments.get(p)
if (attachment !== undefined) {
deleteFile(attachment.file)
}
})
}
}
export async function saveNewAttachment (_id: Ref<Attachment>): Promise<void> {
Expand Down
5 changes: 2 additions & 3 deletions plugins/attachment-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import activity, { type ActivityMessage, type DocUpdateMessage } from '@hcengine
import attachment, { type Attachment } from '@hcengineering/attachment'
import core, { SortingOrder, type Markup, type ObjQueryType, type SortingQuery } from '@hcengineering/core'
import { type IntlString, type Resources } from '@hcengineering/platform'
import { PDFViewer, deleteFile, getClient, uploadFile } from '@hcengineering/presentation'
import { PDFViewer, getClient, uploadFile } from '@hcengineering/presentation'

import AccordionEditor from './components/AccordionEditor.svelte'
import AddAttachment from './components/AddAttachment.svelte'
Expand Down Expand Up @@ -262,8 +262,7 @@ export default async (): Promise<Resources> => ({
AttachmentsUpdatedMessage
},
helper: {
UploadFile: uploadFile,
DeleteFile: deleteFile
UploadFile: uploadFile
},
actionImpl: {
AddAttachmentToSaved,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@
return result
}
export async function removeAvatar (avatar: string) {
if (!avatar.includes('://')) {
const deleteFile = await getResource(attachment.helper.DeleteFile)
await deleteFile(avatar)
}
}
function handlePopupSubmit (
submittedAvatarType: AvatarType,
submittedAvatar: Ref<PlatformBlob> | undefined | null,
Expand Down
2 changes: 0 additions & 2 deletions plugins/gmail-resources/src/components/NewMessage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@
const query = createQuery()
async function removeAttachment (attachment: Attachment): Promise<void> {
const deleteFile = await getResource(attachmentP.helper.DeleteFile)
await client.removeCollection(
attachment._class,
attachment.space,
Expand All @@ -150,7 +149,6 @@
attachment.attachedToClass,
'attachments'
)
await deleteFile(attachment.file)
}
let attachments: Attachment[] = []
Expand Down
2 changes: 0 additions & 2 deletions plugins/gmail-resources/src/components/NewMessages.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
const attachmentsQ = createQuery()
async function removeAttachment (attachment: Attachment): Promise<void> {
const deleteFile = await getResource(attachmentP.helper.DeleteFile)
await client.removeCollection(
attachment._class,
attachment.space,
Expand All @@ -175,7 +174,6 @@
attachment.attachedToClass,
'attachments'
)
await deleteFile(attachment.file)
}
let attachments: Attachment[] = []
Expand Down
14 changes: 1 addition & 13 deletions plugins/recruit-resources/src/components/CreateCandidate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
InlineAttributeBar,
KeyedAttribute,
MessageBox,
MultipleDraftController,
deleteFile
MultipleDraftController
} from '@hcengineering/presentation'
import type { Candidate, CandidateDraft } from '@hcengineering/recruit'
import { recognizeDocument } from '@hcengineering/rekoni'
Expand Down Expand Up @@ -452,16 +451,6 @@
}
}
async function deleteResume (): Promise<void> {
if (object.resumeUuid) {
try {
await deleteFile(object.resumeUuid)
} catch (err) {
console.error(err)
}
}
}
async function createAttachment (file: File) {
loading = true
try {
Expand Down Expand Up @@ -559,7 +548,6 @@
(result?: boolean) => {
if (result === true) {
dispatch('close')
deleteResume()
resetObject()
draftController.remove()
}
Expand Down
8 changes: 1 addition & 7 deletions plugins/tracker-resources/src/components/SubIssues.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<script lang="ts">
import attachment, { Attachment } from '@hcengineering/attachment'
import core, { AttachedData, Doc, Ref, SortingOrder } from '@hcengineering/core'
import { DraftController, draftsStore, getClient, deleteFile } from '@hcengineering/presentation'
import { DraftController, draftsStore, getClient } from '@hcengineering/presentation'
import tags from '@hcengineering/tags'
import { makeRank } from '@hcengineering/task'
import { Component, Issue, IssueDraft, IssueParentInfo, Milestone, Project } from '@hcengineering/tracker'
Expand Down Expand Up @@ -148,12 +148,6 @@
export async function removeDraft (_id: string, removeFiles: boolean = false): Promise<void> {
const draftAttachments = $draftsStore[`${_id}_attachments`]
DraftController.remove(`${_id}_attachments`)
if (removeFiles && draftAttachments) {
for (const key in draftAttachments) {
const attachment = draftAttachments[key as Ref<Attachment>]
await deleteFile(attachment.file)
}
}
}
</script>

Expand Down
30 changes: 1 addition & 29 deletions server-plugins/attachment-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,7 @@
// limitations under the License.
//

import type { Attachment } from '@hcengineering/attachment'
import type { Tx, TxRemoveDoc } from '@hcengineering/core'
import { TxProcessor } from '@hcengineering/core'
import type { TriggerControl } from '@hcengineering/server-core'

/**
* @public
*/
export async function OnAttachmentDelete (
tx: Tx,
{ removedMap, ctx, storageAdapter, workspace }: TriggerControl
): Promise<Tx[]> {
const rmTx = TxProcessor.extractTx(tx) as TxRemoveDoc<Attachment>

// Obtain document being deleted.
const attach = removedMap.get(rmTx.objectId) as Attachment

if (attach === undefined) {
return []
}

await storageAdapter.remove(ctx, workspace, [attach.file])

return []
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default async () => ({
trigger: {
OnAttachmentDelete
}
trigger: {}
})
Loading

0 comments on commit 7a4c1e4

Please sign in to comment.