Perf: remove talkingdata

This commit is contained in:
萌萌哒赫萝
2023-05-18 18:23:56 +08:00
parent 50d8d721ca
commit d9d2a840c4
9 changed files with 5 additions and 95 deletions
+2 -25
View File
@@ -12,8 +12,8 @@ import windowManager from 'apis/app/window/windowManager'
import { IWindowList } from '#/types/enum'
import util from 'util'
import { IPicGo } from 'piclist'
import { showNotification, calcDurationRange, getClipboardFilePath } from '~/main/utils/common'
import { RENAME_FILE_NAME, TALKING_DATA_EVENT } from '~/universal/events/constants'
import { showNotification, getClipboardFilePath } from '~/main/utils/common'
import { RENAME_FILE_NAME } from '~/universal/events/constants'
import logger from '@core/picgo/logger'
import { T } from '~/main/i18n'
import fse from 'fs-extra'
@@ -45,20 +45,6 @@ const waitForRename = (window: BrowserWindow, id: number): Promise<string|null>
})
}
const handleTalkingData = (webContents: WebContents, options: IAnalyticsData) => {
const data: ITalkingDataOptions = {
EventId: 'upload',
Label: options.type,
MapKv: {
by: options.fromClipboard ? 'clipboard' : 'files', // 上传剪贴板图片还是选择的文文件
count: options.count, // 上传的数量
duration: calcDurationRange(options.duration || 0), // 上传耗时
type: options.type
}
}
webContents.send(TALKING_DATA_EVENT, data)
}
class Uploader {
private webContents: WebContents | null = null
// private uploading: boolean = false
@@ -152,17 +138,8 @@ class Uploader {
if (!privacyCheckRes) {
throw Error(T('PRIVACY_TIPS'))
}
const startTime = Date.now()
const output = await picgo.upload(img)
if (Array.isArray(output) && output.some((item: ImgInfo) => item.imgUrl)) {
if (this.webContents) {
handleTalkingData(this.webContents, {
fromClipboard: !img,
type: db.get('picBed.uploader') || db.get('picBed.current') || 'smms',
count: img ? img.length : 1,
duration: Date.now() - startTime
} as IAnalyticsData)
}
output.forEach((item: ImgInfo) => {
item.config = JSON.parse(JSON.stringify(db.get(`picBed.${item.type}`)))
})
-17
View File
@@ -53,23 +53,6 @@ export const showMessageBox = (options: any) => {
})
}
const thresholds = [
{ limit: 1000, value: 500 },
{ limit: 1500, value: 1000 },
{ limit: 3000, value: 2000 },
{ limit: 5000, value: 3000 },
{ limit: 7000, value: 5000 },
{ limit: 10000, value: 8000 },
{ limit: 12000, value: 10000 },
{ limit: 20000, value: 15000 },
{ limit: 30000, value: 20000 }
]
export const calcDurationRange = (duration: number) => {
const foundThreshold = thresholds.find(({ limit }) => duration < limit)
return foundThreshold ? foundThreshold.value : 100000
}
/**
* macOS public.file-url will get encoded file path,
* so we need to decode it