Skip to content

Feature #2439 Add total size and file count display to source tab #2448

Merged
m3nu merged 3 commits intoborgbase:masterfrom
ebuzerdrmz44:source-tab-work
Mar 16, 2026
Merged

Feature #2439 Add total size and file count display to source tab #2448
m3nu merged 3 commits intoborgbase:masterfrom
ebuzerdrmz44:source-tab-work

Conversation

@ebuzerdrmz44
Copy link
Contributor

Description

Added a label to the source tab that displays the aggregate total size and file count
of all configured backup sources. The label updates automatically when sources are
added, removed, or recalculated.

Related Issue

Closes #2439

Motivation and Context

When a profile has multiple source directories, users had to manually calculate the
total size. This adds a simple summary label to make that information immediately visible.

How Has This Been Tested?

  1. Manually verified label updates when adding/removing sources
  2. Verified label updates after recalculate button is clicked
  3. Verified label shows empty when no size data is available
  4. Verified label displays correctly when switching between profiles

Screenshots

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have read the CONTRIBUTING guide.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

I provide my contribution under the terms of the license of this repository and I affirm the Developer Certificate of Origin.

Copy link
Contributor

@m3nu m3nu left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution — this is a nice quality-of-life feature. A few issues to address:

Bug: > 0 should be >= 0 for size/count checks

SourceFileModel.dir_size defaults to -1 (uncalculated sentinel). The current check if source.dir_size > 0 correctly skips uncalculated entries but also skips legitimate zero-byte directories/files. Should be >= 0. Same for dir_files_count.

Additionally, the display check if total_size > 0 has the same problem — if all sources are empty (0 bytes), the label stays blank even though there are valid calculated sources.

Nit: DB query could use Peewee aggregation

update_total_size() loads all SourceFileModel rows into Python and sums manually. A single aggregation query would be cleaner:

from peewee import fn
total_size, total_files = (
    SourceFileModel
    .select(fn.SUM(SourceFileModel.dir_size), fn.SUM(SourceFileModel.dir_files_count))
    .where(SourceFileModel.profile == self.profile(), SourceFileModel.dir_size >= 0)
    .scalar(as_tuple=True)
)
total_size = total_size or 0
total_files = total_files or 0

Not blocking since the number of sources per profile is always small, but worth considering.

Nit: translation format string

"Total Size: {}, {} files" — positional {} placeholders make it harder for translators to reorder words for different languages. Named placeholders would be marginally better:

self.tr("Total Size: {size}, {count} files").format(size=pretty_bytes(total_size), count=total_files)

@ebuzerdrmz44
Copy link
Contributor Author

Appreciate the review,
One question: when no sources have been calculated yet (all dir_size = -1), fn.SUM returns None. Should the label show "Total Size: 0 Bytes, 0 files" or stay empty until at least one source is calculated? I'm leaning towards hiding it until we have real data.

@m3nu
Copy link
Contributor

m3nu commented Mar 16, 2026

Hiding sounds good.

@ebuzerdrmz44 ebuzerdrmz44 requested a review from m3nu March 16, 2026 19:58
m3nu
m3nu previously approved these changes Mar 16, 2026
Copy link
Contributor

@m3nu m3nu left a comment

Choose a reason for hiding this comment

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

All review items addressed. One optional style nit: from peewee import fn could be moved to the top-level imports instead of inside the method body, but not blocking.

LGTM, thanks for the quick turnaround.

"""
Update the total size and files count for all sources.
"""
from peewee import fn
Copy link
Contributor

@m3nu m3nu Mar 16, 2026

Choose a reason for hiding this comment

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

AI often puts imports inside functions. Something you need to look out for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it was inside the function in the previous review, so I just put it there. But thanks for the advice

@ebuzerdrmz44 ebuzerdrmz44 requested a review from m3nu March 16, 2026 20:25
@m3nu m3nu merged commit d8eba47 into borgbase:master Mar 16, 2026
5 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.

add "total size" for sources

2 participants