Skip to content

add link count#564

Merged
dbarzin merged 5 commits intomainfrom
dev
Feb 1, 2026
Merged

add link count#564
dbarzin merged 5 commits intomainfrom
dev

Conversation

@dbarzin
Copy link
Copy Markdown
Owner

@dbarzin dbarzin commented Feb 1, 2026

Summary by CodeRabbit

  • New Features

    • Added Links column with per-row link count (badge when >1) and a Status column showing file existence and hash-validation state (OK / HASH FAILS / MISSING).
  • UI Improvements

    • Trimmed filename link text and made ID inline for cleaner rows.
    • Merged size and hash into a compact inline display with smaller hash text and colored status indicators.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 1, 2026

Warning

Rate limit exceeded

@dbarzin has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 7 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Walkthrough

Controller now precomputes per-document file state (exists, hard-link count, SHA‑256 validity) and the Blade view adds Links and Status columns that render counts/badges and color-coded status based on those attributes.

Changes

Cohort / File(s) Summary
View Template
resources/views/documents/check.blade.php
Added Links and Status columns; simplified filename/size/hash display; switched per-row rendering to use precomputed file_exists, link_count, hash_valid; shows badge/count/hyphen for links and colored span for status (OK / HASH FAILS / MISSING).
Controller Logic
app/Http/Controllers/DocumentController.php
check action now loads documents and maps over them to set file_exists, link_count, compute SHA‑256 and hash_valid before passing to the view.
Translations
resources/lang/.../cruds.php
resources/lang/en/cruds.php, resources/lang/de/cruds.php, resources/lang/fr/cruds.php
Added document -> fields keys: links and status (localized strings).

Sequence Diagram(s)

sequenceDiagram
    participant Browser
    participant Controller as DocumentController
    participant DB as Documents(DB)
    participant FS as Filesystem
    participant View as Blade Template

    Browser->>Controller: GET /documents/check
    Controller->>DB: fetch all documents
    loop per document
        Controller->>FS: stat file (exists?)
        alt file exists
            Controller->>FS: read file -> compute SHA-256
            Controller->>FS: stat -> get hard-link count
            Controller->>Controller: set file_exists=true, link_count, hash_valid=(hash==stored)
        else missing
            Controller->>Controller: set file_exists=false, link_count=0, hash_valid=false
        end
    end
    Controller->>View: render with augmented documents
    View->>Browser: HTML with Links and Status columns
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through folders, sniffed each file’s name,
Counted links, chased hashes, and kept my aim,
Green for OK, red for what failed to show,
Badges for many, hyphens when none grow,
A carrot-cheer — the check’s complete, hooray! 🥕

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'add link count' is partially related to the changeset but does not capture the main purpose. The PR's primary change is adding a status check feature with file validation, not just link count display. Consider a more comprehensive title like 'Add document status check with file validation and link count' to better reflect the overall changes across the controller logic, views, and translations.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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: 2

🤖 Fix all issues with AI agents
In `@resources/views/documents/check.blade.php`:
- Around line 19-31: The view is performing per-row file I/O and hashing (using
file_exists, stat, hash_file) on $documents which will be slow; move this work
into the controller/service (e.g., DocumentsController@index or the service that
fetches $documents) so you compute fileExists, linkCount and hashValid ahead of
rendering (or cache them), attach those values to each document (e.g., replace
$documents with $documentsWithMeta or add metadata properties) and pass that
prepared array to the Blade view so the template only reads the precomputed
values instead of calling file_exists/stat/hash_file.
- Around line 26-30: The current block uses file_exists as a TOCTOU check and
calls stat($filePath) and hash_file('sha256', $filePath) without guarding
against failures; update the guarded section around $fileExists so you first
attempt stat($filePath) and hash_file inside try/if checks and only set
$linkCount and $hashValid when those calls succeed (e.g., ensure $stats is
truthy before using $stats['nlink'] and compute $hashOnlyIf = `@hash_file`(...) or
check is_file/is_readable before hashing), leaving $linkCount defaulted and
$hashValid false when stat/hash_file fail to avoid runtime warnings and
inconsistent state.
🧹 Nitpick comments (1)
resources/views/documents/check.blade.php (1)

40-40: Use a multibyte-safe truncation helper.

substr can break UTF‑8 filenames mid‑character. Prefer Laravel’s helper for safe truncation.

♻️ Suggested change
-            <a href="/doc/show/{{ $doc->id }}">{{ substr($doc->filename, 0, 32) }}</a>
+            <a href="/doc/show/{{ $doc->id }}">{{ \Illuminate\Support\Str::limit($doc->filename, 32) }}</a>

Comment on lines +19 to +31
@foreach ($documents as $doc)
@php
$filePath = storage_path('docs/' . $doc->id);
$fileExists = file_exists($filePath);
$linkCount = 0;
$hashValid = false;

if ($fileExists) {
$stats = stat($filePath);
$linkCount = $stats['nlink'] ?? 0;
$hashValid = ($doc->hash === hash_file('sha256', $filePath));
}
@endphp
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Move per-row file I/O + hashing out of the Blade view.

file_exists, stat, and especially hash_file per document will scale poorly on list pages and can noticeably slow requests when documents or files are large. Consider precomputing these values in the controller/service (or caching them) and passing them into the view.

🤖 Prompt for AI Agents
In `@resources/views/documents/check.blade.php` around lines 19 - 31, The view is
performing per-row file I/O and hashing (using file_exists, stat, hash_file) on
$documents which will be slow; move this work into the controller/service (e.g.,
DocumentsController@index or the service that fetches $documents) so you compute
fileExists, linkCount and hashValid ahead of rendering (or cache them), attach
those values to each document (e.g., replace $documents with $documentsWithMeta
or add metadata properties) and pass that prepared array to the Blade view so
the template only reads the precomputed values instead of calling
file_exists/stat/hash_file.

Comment on lines +26 to +30
if ($fileExists) {
$stats = stat($filePath);
$linkCount = $stats['nlink'] ?? 0;
$hashValid = ($doc->hash === hash_file('sha256', $filePath));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Guard stat/hash_file failures to avoid runtime warnings.

file_exists is a TOCTOU check; the file can disappear between checks, causing stat/hash_file warnings and inconsistent state. Add a defensive guard and only mark hash valid when computation succeeds.

✅ Suggested guard
-        if ($fileExists) {
-            $stats = stat($filePath);
-            $linkCount = $stats['nlink'] ?? 0;
-            $hashValid = ($doc->hash === hash_file('sha256', $filePath));
-        }
+        if ($fileExists) {
+            $stats = `@stat`($filePath);
+            if ($stats !== false) {
+                $linkCount = $stats['nlink'] ?? 0;
+            }
+            $computedHash = `@hash_file`('sha256', $filePath);
+            $hashValid = $computedHash !== false && hash_equals($doc->hash, $computedHash);
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if ($fileExists) {
$stats = stat($filePath);
$linkCount = $stats['nlink'] ?? 0;
$hashValid = ($doc->hash === hash_file('sha256', $filePath));
}
if ($fileExists) {
$stats = `@stat`($filePath);
if ($stats !== false) {
$linkCount = $stats['nlink'] ?? 0;
}
$computedHash = `@hash_file`('sha256', $filePath);
$hashValid = $computedHash !== false && hash_equals($doc->hash, $computedHash);
}
🤖 Prompt for AI Agents
In `@resources/views/documents/check.blade.php` around lines 26 - 30, The current
block uses file_exists as a TOCTOU check and calls stat($filePath) and
hash_file('sha256', $filePath) without guarding against failures; update the
guarded section around $fileExists so you first attempt stat($filePath) and
hash_file inside try/if checks and only set $linkCount and $hashValid when those
calls succeed (e.g., ensure $stats is truthy before using $stats['nlink'] and
compute $hashOnlyIf = `@hash_file`(...) or check is_file/is_readable before
hashing), leaving $linkCount defaulted and $hashValid false when stat/hash_file
fail to avoid runtime warnings and inconsistent state.

Copy link
Copy Markdown
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: 2

🤖 Fix all issues with AI agents
In `@app/Http/Controllers/DocumentController.php`:
- Around line 284-285: stat($filePath) can return false if the file is removed
between file_exists() and stat() (TOCTOU); update the block in
DocumentController (around the $stats = stat($filePath) and $doc->link_count
assignment) to check that $stats !== false (or is_array($stats)) before
accessing $stats['nlink'], and fall back to 0 when stat() failed so
$doc->link_count is always safely assigned.

In `@resources/views/documents/check.blade.php`:
- Around line 14-15: Replace the hardcoded column headers "Links" and "Status"
in the Blade view with translation helpers (e.g. use
trans('cruds.document.fields.links') and trans('cruds.document.fields.status')
or `@lang`(...) in the same locations), and add the corresponding keys ("links"
and "status") under cruds.document.fields in your language files so the labels
render correctly for localized deployments.
🧹 Nitpick comments (1)
app/Http/Controllers/DocumentController.php (1)

274-292: Consider pagination or lazy loading for large document sets.

Document::all() loads the entire table into memory, and each document triggers disk I/O (stat, hash_file). For admin-only diagnostic pages this is acceptable, but if the document count grows significantly, consider adding pagination or a cursor-based approach.

Comment on lines +284 to +285
$stats = stat($filePath);
$doc->link_count = $stats['nlink'] ?? 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Guard stat() return value before array access.

If the file is deleted between the file_exists() check and stat() call (TOCTOU race), stat() returns false. Accessing $stats['nlink'] on false will produce a PHP warning.

🛡️ Proposed fix
             if ($fileExists) {
                 $stats = stat($filePath);
-                $doc->link_count = $stats['nlink'] ?? 0;
+                if ($stats !== false) {
+                    $doc->link_count = $stats['nlink'] ?? 0;
+                }

                 $computedHash = hash_file('sha256', $filePath);
🤖 Prompt for AI Agents
In `@app/Http/Controllers/DocumentController.php` around lines 284 - 285,
stat($filePath) can return false if the file is removed between file_exists()
and stat() (TOCTOU); update the block in DocumentController (around the $stats =
stat($filePath) and $doc->link_count assignment) to check that $stats !== false
(or is_array($stats)) before accessing $stats['nlink'], and fall back to 0 when
stat() failed so $doc->link_count is always safely assigned.

Comment on lines +14 to +15
<th>Links</th>
<th>Status</th>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add translation keys for new column headers.

Other column headers use trans('cruds.document.fields.xxx') for internationalization, but "Links" and "Status" are hardcoded English strings. This breaks consistency for localized deployments.

🌐 Proposed fix
-        <th>Links</th>
-        <th>Status</th>
+        <th>{{ trans('cruds.document.fields.links') }}</th>
+        <th>{{ trans('cruds.document.fields.status') }}</th>

Don't forget to add the corresponding keys to your language files.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<th>Links</th>
<th>Status</th>
<th>{{ trans('cruds.document.fields.links') }}</th>
<th>{{ trans('cruds.document.fields.status') }}</th>
🤖 Prompt for AI Agents
In `@resources/views/documents/check.blade.php` around lines 14 - 15, Replace the
hardcoded column headers "Links" and "Status" in the Blade view with translation
helpers (e.g. use trans('cruds.document.fields.links') and
trans('cruds.document.fields.status') or `@lang`(...) in the same locations), and
add the corresponding keys ("links" and "status") under cruds.document.fields in
your language files so the labels render correctly for localized deployments.

Copy link
Copy Markdown
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: 1

🤖 Fix all issues with AI agents
In `@app/Http/Controllers/DocumentController.php`:
- Around line 283-290: The code calls hash_equals($doc->hash, $computedHash)
without ensuring $doc->hash is a string; update the DocumentController logic so
you only call hash_equals when $doc->hash is a non-null string (e.g.,
is_string($doc->hash) && $doc->hash !== '') or otherwise set $doc->hash_valid to
false (or compare using a safe cast) — change the block around $computedHash and
$doc->hash_valid in the DocumentController to guard $doc->hash before calling
hash_equals and ensure $doc->hash_valid is deterministically set when
legacy/null hashes are present.
🧹 Nitpick comments (1)
app/Http/Controllers/DocumentController.php (1)

285-287: Fix inconsistent indentation on closing brace.

The closing brace on line 287 has extra indentation that doesn't match the opening if statement.

🧹 Proposed fix
                 if ($stats !== false) {
                     $doc->link_count = $stats['nlink'] ?? 0;
-                    }
+                }

Comment thread app/Http/Controllers/DocumentController.php
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@dbarzin dbarzin merged commit 636bb56 into main Feb 1, 2026
1 check 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