mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-06-01 05:30:52 +08:00
Merge branch 'feat/db' into feature/ui
This commit is contained in:
63
packages/sqlite-plugin/src/entity/VChatStartupLog.ts
Normal file
63
packages/sqlite-plugin/src/entity/VChatStartupLog.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { requireTypeorm } from "../utils/module-loader";
|
||||
const { ViewEntity, ViewColumn } = requireTypeorm();
|
||||
@ViewEntity({
|
||||
expression: `SELECT
|
||||
job_info.*,
|
||||
user_info.name as userName,
|
||||
chat_startup_log.date,
|
||||
boss_info.name AS bossName,
|
||||
company_info.name AS companyName
|
||||
FROM
|
||||
chat_startup_log
|
||||
LEFT JOIN job_info ON chat_startup_log.encryptJobId = job_info.encryptJobId
|
||||
LEFT JOIN user_info ON chat_startup_log.encryptCurrentUserId = user_info.encryptUserId
|
||||
LEFT JOIN boss_info ON boss_info.encryptBossId = job_info.encryptBossId
|
||||
LEFT JOIN company_info ON company_info.encryptCompanyId = job_info.encryptCompanyId
|
||||
`,
|
||||
})
|
||||
export class VChatStartupLog {
|
||||
@ViewColumn()
|
||||
encryptJobId: number;
|
||||
|
||||
@ViewColumn()
|
||||
jobName: string;
|
||||
|
||||
@ViewColumn()
|
||||
positionName: string;
|
||||
|
||||
@ViewColumn()
|
||||
salaryLow: number | null;
|
||||
|
||||
@ViewColumn()
|
||||
salaryHeigh: number | null;
|
||||
|
||||
@ViewColumn()
|
||||
salaryMonth: number | null;
|
||||
|
||||
@ViewColumn()
|
||||
experienceName: number | null;
|
||||
|
||||
@ViewColumn()
|
||||
publishDate: Date | null;
|
||||
|
||||
@ViewColumn()
|
||||
degreeName: string;
|
||||
|
||||
@ViewColumn()
|
||||
address: string;
|
||||
|
||||
@ViewColumn()
|
||||
description: string;
|
||||
|
||||
@ViewColumn()
|
||||
userName: string;
|
||||
|
||||
@ViewColumn()
|
||||
date: string;
|
||||
|
||||
@ViewColumn()
|
||||
bossName: string;
|
||||
|
||||
@ViewColumn()
|
||||
companyName: string;
|
||||
}
|
||||
@@ -12,12 +12,13 @@ import { JobInfo } from "./entity/JobInfo";
|
||||
import { JobInfoChangeLog } from "./entity/JobInfoChangeLog";
|
||||
import { BossActiveStatusRecord } from "./entity/BossActiveStatusRecord";
|
||||
import { UserInfo } from "./entity/UserInfo";
|
||||
import { VChatStartupLog } from "./entity/VChatStartupLog";
|
||||
|
||||
import sqlite3 from 'sqlite3';
|
||||
import * as cliHighlight from 'cli-highlight';
|
||||
Boolean(cliHighlight);
|
||||
|
||||
function initDb(dbFilePath) {
|
||||
export function initDb(dbFilePath) {
|
||||
const { DataSource } = requireTypeorm()
|
||||
const appDataSource = new DataSource({
|
||||
type: "sqlite",
|
||||
@@ -36,6 +37,7 @@ function initDb(dbFilePath) {
|
||||
JobInfoChangeLog,
|
||||
BossActiveStatusRecord,
|
||||
UserInfo,
|
||||
VChatStartupLog
|
||||
],
|
||||
});
|
||||
return appDataSource.initialize();
|
||||
|
||||
21
packages/ui/src/common/utils/performance.ts
Normal file
21
packages/ui/src/common/utils/performance.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
export const measureExecutionTime = async <
|
||||
T extends Promise<unknown> | ((...args: unknown[]) => unknown),
|
||||
U = T extends Promise<unknown>
|
||||
? T
|
||||
: T extends (...args: unknown[]) => unknown
|
||||
? ReturnType<T>
|
||||
: never
|
||||
>(
|
||||
promiseOrFunction: T
|
||||
): Promise<U> => {
|
||||
const startTime = new Date()
|
||||
if (promiseOrFunction instanceof Promise) {
|
||||
await promiseOrFunction
|
||||
console.log(`execution duration ${Number(new Date()) - Number(startTime)}ms`)
|
||||
return promiseOrFunction as U
|
||||
} else {
|
||||
const result = await promiseOrFunction()
|
||||
console.log(`execution duration ${Number(new Date()) - Number(startTime)}ms`)
|
||||
return result as U
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import { getAnyAvailablePuppeteerExecutable } from '../../../flow/CHECK_AND_DOWN
|
||||
import { sleep } from '@geekgeekrun/utils/sleep.mjs'
|
||||
import { AUTO_CHAT_ERROR_EXIT_CODE } from '../../../../common/enums/auto-start-chat'
|
||||
import { mainWindow } from '../../../window/mainWindow'
|
||||
import { getAutoStartChatRecord, initDbWorker } from '../utils/db/index'
|
||||
|
||||
export default function initIpc () {
|
||||
ipcMain.on('open-external-link', (_, link) => {
|
||||
@@ -257,4 +258,9 @@ export default function initIpc () {
|
||||
const cookies = readStorageFile('boss-cookies.json')
|
||||
return checkCookieListFormat(cookies)
|
||||
})
|
||||
|
||||
ipcMain.handle('get-auto-start-chat-record', async () => {
|
||||
const a = await getAutoStartChatRecord()
|
||||
console.log(a)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import createDbWorker from './worker/index?nodeWorker&url'
|
||||
import { type Worker } from 'node:worker_threads'
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
let worker: Worker | null = null
|
||||
let workerExitCode: number | null = null
|
||||
export const initDbWorker = () => {
|
||||
if (!worker || typeof workerExitCode === 'number') {
|
||||
worker = createDbWorker()
|
||||
workerExitCode = null
|
||||
return new Promise((resolve, reject) => {
|
||||
worker!.once('exit', (exitCode) => {
|
||||
workerExitCode = exitCode
|
||||
worker = null
|
||||
})
|
||||
worker!.on('message', function handler(data) {
|
||||
if (data.type === 'DB_INIT_SUCCESS') {
|
||||
resolve(worker)
|
||||
// attach more event
|
||||
worker?.off('message', handler)
|
||||
} else if (data.type === 'DB_INIT_FAIL') {
|
||||
reject(undefined)
|
||||
worker?.terminate()
|
||||
worker?.off('message', handler)
|
||||
worker = null
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
return worker
|
||||
}
|
||||
}
|
||||
|
||||
const createWorkerPromise = async (data) => {
|
||||
await initDbWorker()
|
||||
const uuid = randomUUID()
|
||||
worker!.postMessage({
|
||||
_uuid: uuid,
|
||||
...data
|
||||
})
|
||||
return new Promise((resolve) => {
|
||||
worker!.on('message', function handler(data) {
|
||||
const { _uuid, ...payload } = data ?? {}
|
||||
if (_uuid === uuid) {
|
||||
resolve(payload)
|
||||
worker?.off('message', handler)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const getAutoStartChatRecord = async () => {
|
||||
const res = await createWorkerPromise({
|
||||
type: 'getAutoStartChatRecord'
|
||||
})
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import 'reflect-metadata'
|
||||
import { parentPort } from 'node:worker_threads'
|
||||
import { initDb } from '@geekgeekrun/sqlite-plugin'
|
||||
import { type DataSource } from 'typeorm'
|
||||
import { getPublicDbFilePath } from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
||||
import { VChatStartupLog } from '@geekgeekrun/sqlite-plugin/dist/entity/VChatStartupLog'
|
||||
import { measureExecutionTime } from '../../../../../../common/utils/performance'
|
||||
|
||||
const dbInitPromise = initDb(getPublicDbFilePath())
|
||||
let dataSource: DataSource | null = null
|
||||
|
||||
dbInitPromise.then(
|
||||
(_dataSource) => {
|
||||
dataSource = _dataSource
|
||||
attachMessageHandler()
|
||||
parentPort?.postMessage({
|
||||
type: 'DB_INIT_SUCCESS'
|
||||
})
|
||||
},
|
||||
(error) => {
|
||||
parentPort?.postMessage({
|
||||
type: 'DB_INIT_FAIL',
|
||||
error
|
||||
})
|
||||
process.exit(1)
|
||||
}
|
||||
)
|
||||
|
||||
const payloadHandler = {
|
||||
async getAutoStartChatRecord(payload) {
|
||||
const result = await measureExecutionTime(
|
||||
dataSource!
|
||||
.createQueryBuilder()
|
||||
.select('*')
|
||||
.from(VChatStartupLog, 'vChatStartupLog')
|
||||
.getRawMany()
|
||||
)
|
||||
console.log(result)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
async function attachMessageHandler() {
|
||||
parentPort?.on('message', async (event) => {
|
||||
const { _uuid, ...restObj } = event
|
||||
const { type } = event
|
||||
|
||||
if (!dataSource) {
|
||||
await dbInitPromise
|
||||
}
|
||||
const result = await payloadHandler[type](restObj)
|
||||
parentPort?.postMessage({
|
||||
_uuid,
|
||||
data: result
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -52,4 +52,10 @@ onMounted(async () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
electron.ipcRenderer.invoke('get-auto-start-chat-record').then(() => {
|
||||
debugger
|
||||
}, () => {
|
||||
debugger
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user