Skip to content

Conversation

@hagenw
Copy link
Member

@hagenw hagenw commented Jan 5, 2026

Speedup audb.Dependencies._add_meta() and audb.Dependencies._add_attachment() by treating them in the same way as audb.Dependencies._add_media().

Currently, this fails as it would require that the meta or attachment to be added is not already stored in the dependency table. It seems our implementation makes use of the fact that we can overwrite the row for meta and attachment.

Summary by Sourcery

Unify how dependency rows are added for media, meta, and attachments by introducing a shared row insertion helper.

Enhancements:

  • Introduce a generic _add_rows() helper for inserting dependency table rows.
  • Update _add_meta() and _add_attachment() to use the same bulk row insertion logic as _add_media() for consistency and potential performance improvements.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 5, 2026

Reviewer's Guide

Refactors how meta and attachment dependencies are added by routing them, along with media entries, through a shared _add_rows() helper that builds and appends a typed DataFrame of new rows for performance and consistency.

Class diagram for updated Dependencies row insertion helpers

classDiagram
    class Dependencies {
        DataFrame _df
        _set_dtypes(df)
        _add_attachment(file, archive, checksum, version)
        _add_media(values)
        _add_meta(file, checksum, version)
        _add_rows(rows)
    }

    class DataFrame
    class DefineModule {
        DEPENDENCY_TABLE
        DEPENDENCY_TYPE
    }

    Dependencies --> DataFrame : uses
    Dependencies --> DefineModule : uses

    class AddRowsTuple {
        str file
        str archive
        int bit_depth
        int channels
        str checksum
        float duration
        str format
        int removed
        float sampling_rate
        int type
        str version
    }

    Dependencies ..> AddRowsTuple : constructs rows
Loading

Flow diagram for adding dependency rows via _add_rows

flowchart TD
    A[_add_attachment] --> B[build single attachment tuple list]
    A2[_add_meta] --> C[build single meta tuple list]
    A3[_add_media] --> D[receive list of media tuples]

    B --> E[_add_rows]
    C --> E
    D --> E

    E --> F[build DataFrame from records
columns: file + DEPENDENCY_TABLE keys]
    F --> G[set dtypes via _set_dtypes]
    G --> H[concat new DataFrame to _df]
Loading

File-Level Changes

Change Details Files
Route _add_attachment() through a new shared row-adding helper instead of assigning directly into the dependencies DataFrame.
  • Compute the attachment format from the file extension as before.
  • Build a single-row values list containing file and dependency metadata fields.
  • Call the shared _add_rows() helper with the constructed values instead of using DataFrame .loc assignment.
audb/core/dependencies.py
Route _add_meta() through the shared row-adding helper and keep archive resolution logic intact.
  • Determine the archive name from the meta file path, preserving the existing filename parsing logic for different meta prefixes.
  • Construct a values tuple with file and dependency metadata fields including type set to meta.
  • Call the shared _add_rows() helper with the constructed values instead of using DataFrame .loc assignment.
audb/core/dependencies.py
Introduce _add_rows() as a common implementation used by _add_media(), _add_meta(), and _add_attachment() to efficiently append dependency rows.
  • Define _add_rows() to accept a sequence of tuples representing full dependency table rows including the file name.
  • Create a DataFrame from the given rows with "file" as index and dependency table columns derived from define.DEPENDENCY_TABLE.
  • Apply _set_dtypes() to the new DataFrame and concatenate it with the existing dependencies DataFrame to append rows in batch.
  • Refactor _add_media() to delegate to _add_rows() instead of duplicating DataFrame construction logic.
audb/core/dependencies.py

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

@hagenw hagenw self-assigned this Jan 5, 2026
@hagenw
Copy link
Member Author

hagenw commented Jan 5, 2026

The current implementation does not really bring a boost, so we will close here.

@hagenw hagenw closed this Jan 5, 2026
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.

2 participants