Skip to content

fix(CardUpload): add duplicate filter logic#7430

Merged
ArgoZhang merged 2 commits intomainfrom
fix-card-upload
Dec 26, 2025
Merged

fix(CardUpload): add duplicate filter logic#7430
ArgoZhang merged 2 commits intomainfrom
fix-card-upload

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Dec 26, 2025

Link issues

fixes #7418

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Prevent duplicate upload entries when combining cached uploads with the current upload list.

Bug Fixes:

  • Avoid adding duplicate files to the internal upload cache when merging the current UploadFiles collection with the existing cache.

Enhancements:

  • Tidy DropUpload preview list markup for better readability.

Copilot AI review requested due to automatic review settings December 26, 2025 04:26
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Dec 26, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Implements duplicate filtering when merging runtime upload files into the cached upload file list, and makes a minor formatting adjustment in the DropUpload preview list markup.

Sequence diagram for GetUploadFiles duplicate filtering logic

sequenceDiagram
    participant Caller
    participant UploadBase
    participant filesCache as _filesCache
    participant DefaultFileList
    participant UploadFiles

    Caller->>UploadBase: GetUploadFiles()
    alt _filesCache is null
        UploadBase->>UploadBase: Initialize _filesCache as new List
        alt DefaultFileList not null
            UploadBase->>filesCache: AddRange(DefaultFileList)
        end
        loop for each file in UploadFiles
            UploadBase->>filesCache: Contains(file)?
            alt file not in _filesCache
                UploadBase->>filesCache: Add(file)
            end
        end
    end
    UploadBase-->>Caller: _filesCache
Loading

Class diagram for UploadBase GetUploadFiles changes

classDiagram
    class UploadBase {
        - List~UploadFile~ _filesCache
        - List~UploadFile~ DefaultFileList
        - List~UploadFile~ UploadFiles
        + List~UploadFile~ GetUploadFiles()
    }

    class UploadFile {
    }

    UploadBase --> UploadFile : uses
Loading

File-Level Changes

Change Details Files
Prevent duplicate UploadFile entries when building the upload files cache.
  • Replace unconditional AddRange(UploadFiles) with a per-file add guarded by a Contains check against the cache.
  • Reuse the existing _filesCache list by only appending new UploadFiles that are not already present, instead of appending all UploadFiles every time GetUploadFiles runs.
src/BootstrapBlazor/Components/Upload/UploadBase.cs
Minor layout/formatting tweak in DropUpload preview list markup.
  • Reformat UploadPreviewList tag attributes across multiple lines for readability without changing behavior.
  • Normalize file header/namespace line (BOM/license/namespace alignment).
src/BootstrapBlazor/Components/Upload/DropUpload.razor

Assessment against linked issues

Issue Objective Addressed Explanation
#7418 Ensure that CardUpload/Upload used with DefaultFileList inside ValidateForm does not throw exceptions and correctly handles the uploaded file list (including avoiding problematic duplication between DefaultFileList and current UploadFiles).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto Bot added the chore This are tasks or bot action label Dec 26, 2025
@bb-auto bb-auto Bot added this to the v10.1.0 milestone Dec 26, 2025
@ArgoZhang ArgoZhang merged commit 67d4b2a into main Dec 26, 2025
5 of 6 checks passed
@ArgoZhang ArgoZhang deleted the fix-card-upload branch December 26, 2025 04:26
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The duplicate check in GetUploadFiles relies on reference equality via List.Contains, which may not prevent logical duplicates if UploadFile instances are reconstructed; consider using a key-based comparison (e.g., by name/ID) or a custom IEqualityComparer to ensure true de-duplication.
  • Using UploadFiles.ForEach with List.Contains inside introduces an O(n²) pattern when the number of files grows; consider using a HashSet or pre-building a lookup keyed by the relevant file identifier to make the merge linear-time.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The duplicate check in `GetUploadFiles` relies on reference equality via `List.Contains`, which may not prevent logical duplicates if `UploadFile` instances are reconstructed; consider using a key-based comparison (e.g., by name/ID) or a custom `IEqualityComparer` to ensure true de-duplication.
- Using `UploadFiles.ForEach` with `List.Contains` inside introduces an O(n²) pattern when the number of files grows; consider using a `HashSet` or pre-building a lookup keyed by the relevant file identifier to make the merge linear-time.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6a17658) to head (7212ff0).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7430   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          748       748           
  Lines        32801     32807    +6     
  Branches      4552      4552           
=========================================
+ Hits         32801     32807    +6     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds duplicate filter logic to prevent duplicate files from being added to the upload file cache. The implementation changes how files are aggregated in the GetUploadFiles method by checking for duplicates before adding them.

  • Replaced AddRange with a ForEach loop that checks for duplicates using Contains before adding files
  • Applied code formatting in DropUpload.razor

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/BootstrapBlazor/Components/Upload/UploadBase.cs Modified GetUploadFiles method to add duplicate filtering logic when combining DefaultFileList and UploadFiles
src/BootstrapBlazor/Components/Upload/DropUpload.razor Code formatting change - split long attribute line across multiple lines

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

_filesCache.AddRange(UploadFiles);
UploadFiles.ForEach(f =>
{
if (!_filesCache.Contains(f))
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

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

The Contains method will only perform reference equality checks since UploadFile class does not override Equals and GetHashCode. This means the duplicate filter will only prevent adding the exact same object instance, not duplicate files with the same content or properties. If the intent is to prevent duplicate files based on file properties (e.g., FileName, OriginFileName, or File reference), you should either override Equals/GetHashCode in the UploadFile class or use a different comparison method such as LINQ's Any with a custom predicate.

Copilot uses AI. Check for mistakes.
Comment on lines +286 to +292
UploadFiles.ForEach(f =>
{
if (!_filesCache.Contains(f))
{
_filesCache.Add(f);
}
});
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

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

The new duplicate filter logic lacks test coverage. Consider adding a test case that verifies files are properly deduplicated when the same UploadFile instances are added to both DefaultFileList and UploadFiles, or when GetUploadFiles is called multiple times.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore This are tasks or bot action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(CardUpload): DefaultFileList 参数在 ValidateForm 中可能引发异常

2 participants