qq_38176614 2022-03-17 14:10
浏览 6
已结题

使用electron+Dexie.js在mac上运行很慢,在windows上运行流畅?

问题遇到的现象和发生背景

为什么使用electron+electron-vue+Dexie.js在mac上运行很慢(占用cpu90%,且很不稳定),在windows上运行流畅?
希望工友们给点建议
问题是一涉及到数据库操作,占用率直接就炸了

问题相关代码
--db.js
import Dexie from 'dexie';
export class User extends Dexie {
    static getInstance(name) {
        return new User(name)
    }
    constructor(name) {
        // run the super constructor Dexie(databaseName) to create the IndexedDB
        // database.
        super(name || `User`);
        this.version(1).stores({
            chatInRooms: 'roomIdAndId,roomId,topStatus,msgDoNotDisturb,avatar,resend,isFirst,lastReadMsgId,isOffLineMsg,logo,msg,msgCount,nikeName,name,msgType,sendTime,msgId,unReadNum',
            chatLocalMsg: 'msgId,roomIdAndId,isTips,isMine,msg,msgType,isRead,isResending,replyType,sendTime,photo,nikeName,redStatus',
        });

        this.open()
        this.chatInRooms = this.table('chatInRooms')
        this.chatLocalMsg = this.table('chatLocalMsg')
    }
}
import { User, realDBName } from "./db";
export default class chatLocalMsgDAO {
    static getInstance() {
        return new chatLocalMsgDAO();
    }
    getUserInstance() {
        let name = realDBName();
        return User.getInstance(name);
    }
    newInfo() {
        return this.getUserInstance().chatLocalMsg;
    }
    get(option = {}) {
        let order = option.order || "msgId";
        return this.newInfo()
            .orderBy(order)
            .reverse()
            .toArray();
    }
    add(item) {
        this.find(item.msgId).then((result) => {
            if (!result) {
                return this.newInfo().add({...item });
            } else {
                //return this.newInfo().update(item.msgId, { ...item });
            }
        })

    }
}

--使用

let getInstance = chatLocalMsgDAO.getInstance();
    getInstance.find(offLineData.msgId).then(result => {
        if (!result) {
            offLineData.roomId = zid
            offLineData.id = zid
            offLineData.roomIdAndId = setRoomIdsId(offLineData.roomId, offLineData.roomType)
            chatLocalMsgDAO.getInstance().add(offLineData);
            Bus.$emit("imgList", offLineData.roomIdAndId)
            getInstance
                .get()
                .then((result) => {})
                .catch((e) => {
                    console.log("err_or: ", e);
                });
        }
    })
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果

cpu 占用率降低且文档

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 3月25日
    • 创建了问题 3月17日

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看