Skip to content

Add folder hash for quick scan detection #4220

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

Merged
merged 4 commits into from
Jun 12, 2025

Conversation

deluan
Copy link
Member

@deluan deluan commented Jun 12, 2025

Summary

Smarter quick scan change detection, using a hash of the information from the folder, not just the ModTime of the folder.

  • add Hash column to folder table and migration
  • include folder hash in scanning logic
  • compare folder hashes to detect outdated folders
  • add unit tests for hashing and outdated logic

Testing

  • make test

https://chatgpt.com/codex/tasks/task_b_684aef16bbb8832e9ac41836e89087d0

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @deluan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant optimization to the library scanning process. By adding a hash to each folder entry in the database, the scanner can now quickly determine if a folder's contents have changed without needing to perform a full directory walk and comparison every time. This should drastically speed up subsequent scans after the initial full scan.

Highlights

  • Database Schema Change: Adds a new hash column to the folder table via a database migration to store a hash representing the folder's content state.
  • Folder Hashing Logic: Implements a method (folderEntry.hash()) to calculate an MD5 hash for a folder based on its modification time, sorted lists of audio and image file names, number of playlists, number of subfolders, and image update timestamp. This hash provides a quick way to check if relevant folder contents have changed.
  • Optimized Scan Detection: Modifies the scanning logic (folderEntry.isOutdated()) to use the stored folder hash. A folder is now considered 'outdated' (requiring a full rescan) if it was last updated before a full scan started OR if its current calculated hash differs from the previously stored hash.
  • Data Model and Repository Updates: Introduces a FolderUpdateInfo struct to hold both the UpdatedAt time and the new Hash. The FolderRepository.GetLastUpdates method is updated to return this new struct, allowing the scanner to retrieve the previous hash along with the last update time.
  • Unit Tests: Adds new unit tests for the folder hashing logic to ensure it produces stable hashes regardless of file order, and tests the updated isOutdated() logic to verify it correctly identifies changes based on the hash.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a folder hashing mechanism to speed up the detection of outdated folders during library scans. This involves adding a Hash column to the folder table, updating data models and repositories, and integrating the hash comparison into the scanning logic. Unit tests for the hashing and outdated detection have also been added.

The review identified a key issue with the database migration's down function, which needs to be implemented to ensure schema changes can be properly rolled back. Additionally, a potential performance optimization regarding redundant hash computations in the scanning logic was noted.

Signed-off-by: Deluan <deluan@navidrome.org>
@deluan deluan marked this pull request as ready for review June 12, 2025 17:11
@deluan deluan requested a review from Copilot June 12, 2025 17:11
Copy link
Contributor

@Copilot 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 enhances the quick scan detection by introducing a folder hash mechanism to determine if a folder is outdated based on its current contents rather than just its modification time. Key changes include:

  • Adding a new "Hash" column to the folder table and corresponding migration.
  • Updating the scan logic to compute a hash from folder attributes.
  • Introducing unit tests to verify the new folder hash functionality.

Reviewed Changes

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

Show a summary per file
File Description
scanner/walk_dir_tree.go Removal of redundant folderEntry definitions now replaced by folder_entry.go
scanner/phase_1_folders.go Updated lastUpdates map to use FolderUpdateInfo instead of time.Time
scanner/folder_entry.go New implementation for folderEntry with folder hash calculation
persistence/folder_repository.go Updated GetLastUpdates to return FolderUpdateInfo including the hash
model/folder.go Added new "Hash" field and introduced FolderUpdateInfo type
db/migrations/20250701010101_add_folder_hash.go New migration for adding the folder hash column to the database

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@deluan deluan merged commit 0d74d36 into master Jun 12, 2025
20 checks passed
@deluan deluan deleted the a11x9q-codex/add-hash-calculation-for-folder-info branch June 12, 2025 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant