Skip to content

fix(vnote): use folder ids for notebook operations#402

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
dengzhongyuan365-dev:bug-fix-7-10
Jul 9, 2026
Merged

fix(vnote): use folder ids for notebook operations#402
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
dengzhongyuan365-dev:bug-fix-7-10

Conversation

@dengzhongyuan365-dev

Copy link
Copy Markdown
Member

Unify notebook operations across QML/C++ on stable folderId semantics instead of mixing UI indexes with internal sort indexes.\n\nAlso reset empty-folder startup/delete state to the initial create page and add a regression checklist for affected PMS bugs.\n\nLog: 修复记事本删除、移动和空状态下 folderId/index 语义错位问题\nInfluence: 记事本删除、移动笔记数量、快速创建笔记归属、空列表初始页和相关回归清单。

pms: BUG-320469

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @dengzhongyuan365-dev, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

Unify notebook operations across QML/C++ on stable folderId semantics instead of mixing UI indexes with internal sort indexes.\n\nAlso reset empty-folder startup/delete state to the initial create page and add a regression checklist for affected PMS bugs.\n\nLog: 修复记事本删除、移动和空状态下 folderId/index 语义错位问题\nInfluence: 记事本删除、移动笔记数量、快速创建笔记归属、空列表初始页和相关回归清单。

pms: BUG-320469
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "src/common/VNoteMainManager.cpp": [
        {
            "line": "            url = \"https://www.deepin.org/zh/agreement/privacy/\";",
            "line_number": 1676,
            "rule": "S35",
            "reason": "Url link | 20e2eab189"
        },
        {
            "line": "            url = \"https://www.uniontech.com/agreement/privacy-cn\";",
            "line_number": 1678,
            "rule": "S35",
            "reason": "Url link | 4850a00dd7"
        },
        {
            "line": "            url = \"https://www.deepin.org/en/agreement/privacy/\";",
            "line_number": 1682,
            "rule": "S35",
            "reason": "Url link | 38d42f63bf"
        },
        {
            "line": "            url = \"https://www.uniontech.com/agreement/privacy-en\";",
            "line_number": 1684,
            "rule": "S35",
            "reason": "Url link | f82409d3b5"
        }
    ]
}

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:93分

■ 【总体评价】

代码通过引入基于folderId的API显著提升了索引稳定性和空指针安全性,但存在重复日志和信号发射条件不严谨等轻微质量瑕疵
逻辑正确且无安全漏洞,因renameFolderById重复日志输出和doCreateNote信号条件问题扣7分

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓
    loadNotepads()中排序清洗逻辑完善,使用QSet去重和realFolderIds验证有效;getFloderIndexById()新增了lockForRead保护,修复了原代码无锁访问folders->folders的竞态风险;getFloderById()新增folder空指针检查防止解引用崩溃;vNoteDeleteFolderById()正确处理了folder为null时的stale UI cleanup场景,包括清理m_currentFolderIndex和m_noteItems
    潜在问题:doCreateNote(int folderId)中emit addNoteAtHead(data)在非当前文件夹时仍无条件发射,可能导致UI端误显示不属于当前文件夹的笔记;moveNotesToFolderId中firstSrcFolderId仅记录第一个源文件夹,多源文件夹场景下信号参数不够精确
    建议:doCreateNote中addNoteAtHead信号应增加isCurrentFolder条件判断,或在UI端根据FOLDER_ID_KEY过滤;moveFinishedByFolderId可考虑传递所有源文件夹ID列表而非仅第一个
  • 2.代码质量(良好)✓
    新增匿名命名空间封装folderIdKey和folderCountsForIds辅助函数,减少全局污染;全面的qDebug/qWarning/qInfo日志覆盖关键路径;QML端deleteFolderAtIndex函数封装了完整的删除后索引恢复逻辑,替代了原先分散的重复代码;RecordingView.qml将height/width改为implicitHeight/implicitWidth修复了布局覆盖问题
    潜在问题:renameFolderById()中qInfo()<<"Folder rename by ID finished"在if分支和函数末尾重复输出;loadNotepads()和updateSortByFolderIds()中多次遍历folders->folders可合并
    建议:删除renameFolderById中if分支内的重复qInfo行;updateSortByFolderIds中第二次和第三次遍历folders可合并为一次
  • 3.代码性能(良好)✓
    loadNotepads中仅在value != m_folderSort.join(",")时才调用setOption避免不必要写入;folderCountsForIds使用QSet避免重复计算;moveNotesToFolderId使用movedCount计数替代原index.size()确保只增加实际移动数量
    建议:updateSortByFolderIds中两次lockForRead之间可合并遍历逻辑减少锁获取次数
  • 4.代码安全(存在0个安全漏洞)✓
    漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
    代码对所有外部输入(持久化排序字符串、QML传入的folderId列表)均通过toLongLong(&ok)和realFolderIds.contains()双重验证;无命令注入、SQL注入、路径遍历等攻击面;锁使用规范,folderCountsForIds中嵌套锁不会导致死锁(不同锁对象)

  • 建议:无需额外安全修复

■ 【改进建议代码示例】

// 修复renameFolderById重复日志
void VNoteMainManager::renameFolderById(const int &folderId, const QString &name)
{
    qDebug() << "Renaming folder with ID" << folderId << "to:" << name;
    VNoteFolder *folder = getFloderById(folderId);
    if (folder && name != folder->name) {
        VNoteFolderOper folderOper(folder);
        folderOper.renameVNoteFolder(name);
    } else {
        qWarning() << "Invalid folder rename operation";
    }
    qInfo() << "Folder rename by ID finished";
}

// 修复doCreateNote中addNoteAtHead信号条件
void VNoteMainManager::doCreateNote(int folderId)
{
    VNoteFolder *currentFolder = getFloderById(folderId);
    if (currentFolder == nullptr) {
        qWarning() << "Cannot create note: target folder not found for ID:" << folderId;
        return;
    }
    qDebug() << "Creating new note in folder ID:" << folderId;
    VNoteItem tmpNote;
    tmpNote.folderId = folderId;
    tmpNote.noteType = VNoteItem::VNT_Text;
    tmpNote.htmlCode = "<p><br></p>";
    VNoteItemOper noteOper;
    VNoteItem *newNote = noteOper.addNote(tmpNote);
    if (!newNote) {
        qWarning() << "Create note failed: addNote returned null";
        return;
    }

    const bool isCurrentFolder = (folderId == m_currentFolderIndex);
    if (isCurrentFolder) {
        m_currentNoteId = newNote->noteId;
        m_noteItems.append(newNote);
    }

    QVariantMap data;
    data.insert(NOTE_NAME_KEY, newNote->noteTitle);
    data.insert(NOTE_COUNT_KEY, QString::number(newNote->noteId));
    data.insert(NOTE_TIME_KEY, newNote->noteCreateTime);
    data.insert(NOTE_FOLDER_ID_KEY, QString::number(currentFolder->id));
    data.insert(NOTE_FOLDER_ICON_KEY, QString::number(currentFolder->defaultIcon));
    data.insert(NOTE_FOLDER_NAME_KEY, currentFolder->name);
    data.insert(NOTE_ID_KEY, newNote->noteId);
    data.insert(FOLDER_ID_KEY, folderId);

    if (isCurrentFolder) {
        emit addNoteAtHead(data);
        if (m_richTextManager)
            m_richTextManager->initData(newNote, "", true);
    }
    qInfo() << "Note creation finished";
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dengzhongyuan365-dev, lzwind

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@dengzhongyuan365-dev

Copy link
Copy Markdown
Member Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 1fe678a into linuxdeepin:develop/snipe Jul 9, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants