Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make diskmanager package respect locked clips during cleanup #455

Merged
merged 2 commits into from
Feb 15, 2025

Conversation

tphakala
Copy link
Owner

Audio clips of locked detections are not removed during disk cleanup process

- Introduce database interface to retrieve locked note clip paths
- Modify audio file cleanup to skip locked clips
- Add locked file tracking in file information structure
- Extend cleanup methods to respect locked clip protection
- Update file scanning to check for locked clips during retention policy processing
- Extend mockStore to include GetLockedNotesClipPaths method
- Prepare test infrastructure for locked notes clip path retrieval
Copy link
Contributor

coderabbitai bot commented Feb 15, 2025

Walkthrough

The changes integrate a datastore interface for enhanced audio clip cleanup and locked file management. Function signatures across the analysis and disk management modules have been updated to pass this datastore parameter. New methods are introduced to retrieve locked note clip paths, and additional logic is implemented to prevent deletion of locked files. These modifications standardize the handling of audio files and ensure better coordination between file processing and database interactions.

Changes

File(s) Change Summary
internal/analysis/realtime.go Updated startClipCleanupMonitor and clipCleanupMonitor to accept a dataStore datastore.Interface parameter for direct datastore access.
internal/datastore/interfaces.go Added method GetLockedNotesClipPaths() to return clip paths from locked notes.
internal/diskmanager/file_utils.go Introduced allowedFileTypes, added Locked field to FileInfo, defined a new interface with GetLockedNotesClipPaths(), added helper functions getLockedClips and isLockedClip, and updated GetAudioFiles to use the datastore.
internal/diskmanager/policy_age.go
internal/diskmanager/policy_usage.go
Modified AgeBasedCleanup and UsageBasedCleanup to include a db Interface parameter and added logic to skip locked files using allowedFileTypes.
internal/imageprovider/imageprovider_test.go Extended mockStore with the new GetLockedNotesClipPaths() method for testing purposes.

Sequence Diagram(s)

sequenceDiagram
    participant RT as RealTimeAnalysis
    participant SC as startClipCleanupMonitor
    participant CCM as clipCleanupMonitor
    participant DM as DiskManager
    participant FU as FileUtils
    participant DB as datastore Interface

    RT->>SC: Invoke with datastore parameter
    SC->>CCM: Start clip cleanup monitor (passes datastore)
    CCM->>DM: Call AgeBased/UsageBasedCleanup with datastore
    DM->>FU: Request GetAudioFiles(baseDir, allowedFileTypes, db, debug)
    FU->>DB: Fetch locked clip paths via getLockedClips()
    DB-->>FU: Return list of locked clips
    FU->>DM: Provide FileInfo list with Locked status
Loading

Possibly related PRs

Poem

Hopping through the code with glee,
A datastore twist now sets functions free.
Locked clips whisper, "I’m safe today!"
Cleanup dances as bugs scurry away.
With ears perked high, I cheer — hip, hop, hooray!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
internal/diskmanager/file_utils.go (3)

17-18: Consider making file extension settings configurable.
Currently, allowedFileTypes is hardcoded, which might be sufficient for your immediate needs. However, externalizing or centralizing this list in configuration can improve flexibility for future changes.


30-33: Consider renaming the interface for clarity.
Naming the interface simply as Interface might lead to confusion and reduce clarity. Give it a more descriptive name (e.g., DatastoreInterface, LockedClipProvider, etc.) to clearly convey its purpose.


69-69: Evaluate parameter ordering in the function signature.
Passing db in the middle can be slightly confusing. Consider grouping parameters into a struct or reordering them to improve readability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 76ec688 and 2e2767e.

📒 Files selected for processing (6)
  • internal/analysis/realtime.go (4 hunks)
  • internal/datastore/interfaces.go (2 hunks)
  • internal/diskmanager/file_utils.go (4 hunks)
  • internal/diskmanager/policy_age.go (3 hunks)
  • internal/diskmanager/policy_usage.go (3 hunks)
  • internal/imageprovider/imageprovider_test.go (1 hunks)
🔇 Additional comments (17)
internal/diskmanager/file_utils.go (6)

27-28: Field addition looks good.
Introducing the Locked field is an effective way to mark protected files and prevent their deletion.


72-77: Fetching locked clips is correctly handled.
Graceful handling of potential database errors helps maintain code robustness.


78-80: Debug logs offer helpful insights.
Including the count of locked clips can be invaluable for auditing and troubleshooting.


93-94: Verify use of filename-only comparisons.
Currently, isLockedClip sets Locked by matching just the file’s base name against locked paths. If two different directories contain files with identical names, this logic might incorrectly lock or unlock them. Confirm that ignoring directory structure is correct for your workflow.


175-181: Helper function is concise and clear.
The getLockedClips function gracefully handles a nil interface check and delegates retrieval to the datastore.


183-193: Double-check directory-level distinction for locked clips.
As mentioned, this function only compares the base filenames against locked ones. Ensure you won’t encounter collisions if identical filenames exist in different directories.

internal/diskmanager/policy_age.go (3)

15-15: Update to accept a datastore interface is appropriate.
Allowing the function to query locked clips is foundational to ensuring that they aren’t deleted prematurely.


33-34: Using the shared list of allowed file types is consistent.
Switching to allowedFileTypes keeps the logic centralized in a single location.


60-66: Correctly skipping locked files.
This approach neatly prevents protected clips from being removed.

internal/diskmanager/policy_usage.go (3)

21-21: Enhanced function signature is well-aligned.
Allowing UsageBasedCleanup to leverage a database parameter ensures locked clips are respected.


49-50: Loading filtered files via allowedFileTypes.
Delegating the file type list to file_utils.go promotes consistency across cleanup policies.


86-92: Skipping locked files is effectively integrated.
Adhering to the new Locked field ensures these clips remain untouched during usage-based cleanup.

internal/analysis/realtime.go (2)

157-157: LGTM! Passing datastore to cleanup monitor.

The change correctly passes the datastore instance to the cleanup monitor, enabling it to check for locked clips during cleanup.


281-281: LGTM! Passing datastore to cleanup functions.

The changes correctly pass the datastore instance to both cleanup functions, enabling them to respect locked clips during cleanup.

Also applies to: 288-288

internal/imageprovider/imageprovider_test.go (1)

169-169: LGTM! Mock implementation of GetLockedNotesClipPaths.

The mock implementation correctly implements the required interface method with a minimal implementation suitable for testing.

internal/datastore/interfaces.go (2)

58-58: LGTM! New interface method for retrieving locked clip paths.

The interface is correctly extended with the new method to support the locked clips feature.


879-895: LGTM! Well-structured implementation of GetLockedNotesClipPaths.

The implementation efficiently retrieves locked clip paths:

  • Uses JOIN to get locked notes in a single query
  • Filters out notes without clips
  • Returns only the clip paths using Pluck
  • Includes proper error handling

@tphakala tphakala merged commit 5da40c4 into main Feb 15, 2025
11 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.

1 participant