Repository navigation
Conversation
…duplicates Enhance backup logging by implementing fingerprint tracking to avoid duplicates
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughBackup callbacks now pass fingerprints through deduplicating logging. Fingerprints are checked against locks and Stream metadata. Backup timestamps update only after confirmed logging. Site and network ID lookups are normalized. ChangesBackup fingerprint flow
Site and network lookup handling
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant BackupCallback
participant MainWPBackups
participant WordPressOptions
participant Stream
participant Connector
BackupCallback->>MainWPBackups: pass backup fingerprint
MainWPBackups->>WordPressOptions: acquire fingerprint lock
MainWPBackups->>Stream: check backup_fingerprint metadata
MainWPBackups->>Connector: insert deduplicated backup record
MainWPBackups->>WordPressOptions: release fingerprint lock
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@classes/class-mainwp-child-report-helper.php`:
- Around line 367-368: Update the static call in the fingerprint check to use
the namespaced WP_MainWP_Stream\Connector_MainWP_Backups class validated by
class_exists(), so was_fingerprint_logged() succeeds and
mainwp_lasttime_backup_updraftplus is updated.
In `@connectors/class-connector-mainwp-backups.php`:
- Around line 270-274: Update the fingerprint condition after Connector::log()
so FINGERPRINT_OPTION is modified only when log() returns a truthy confirmed
Stream insert result, preventing null results from indexing skipped records. Use
the existing $result value and preserve the fingerprint non-empty check.
- Around line 260-274: Update log_backup to reserve the fingerprint atomically
instead of doing a separate fingerprint_exists check before insert, since
concurrent calls can race between the check, Stream write, and option update.
Use a single lock or unique reservation mechanism around the fingerprint path in
log_backup so only one callback can claim a given fingerprint at a time. Keep
the existing backup_fingerprint assignment and option write flow, but release or
roll back the reservation if $this->log() fails or returns a WP_Error so failed
inserts do not block future retries.
- Around line 272-274: Bound the recent-fingerprint cache in the backup flow
around the fingerprint option update in the MainWP backups connector, since the
current get_option/self::FINGERPRINT_OPTION array grows without limit and
rewrites the full payload on every backup. Update the code that adds
$fingerprint to the cache to prune older entries before update_option(), using
the existing fingerprint handling path in this connector. Preserve the metadata
fallback for fingerprints that are evicted from the cache so previously stored
backups can still be recognized.
- Around line 297-304: Update the fallback fingerprint lookup in the surrounding
deduplication method to join mainwp_stream_meta with mainwp_stream on record_id,
then constrain the query using get_current_site()->id and get_current_blog_id().
Preserve the existing backup_fingerprint and fingerprint matching while ensuring
identical fingerprints from other sites or blogs do not suppress logging.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5603a9f3-6709-4e6e-90d3-fd45c5ba5c6d
📒 Files selected for processing (3)
classes/class-connector.phpclasses/class-mainwp-child-report-helper.phpconnectors/class-connector-mainwp-backups.php
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@connectors/class-connector-mainwp-backups.php`:
- Around line 274-301: Update the fingerprint lock handling around the lock
acquisition and cleanup in the enclosing logging method to use an atomically
reclaimable lease with an expiration time, allowing later deliveries to replace
only expired locks without overwriting active ones. After successful
acquisition, register shutdown cleanup for the specific lock so abnormal
termination removes it when possible; retain normal-path deletion and ensure
cleanup does not remove a newer owner’s lock.
- Around line 325-333: Update the fallback metadata lookup in the fingerprint
query to use the effective blog ID passed through the same logging filter as
classes/class-log.php, rather than the raw get_current_blog_id() value. Apply
the existing wp_mainwp_stream_blog_id_logged filter before supplying the blog ID
to the SQL parameters, while preserving the current site ID and fingerprint
matching.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ae36c62b-5d81-4325-b8d0-8e44c95322ef
📒 Files selected for processing (2)
classes/class-mainwp-child-report-helper.phpconnectors/class-connector-mainwp-backups.php
🚧 Files skipped from review as they are similar to previous changes (1)
- classes/class-mainwp-child-report-helper.php
…d enhance reliability
…ints and updating cache logic to improve performance and reliability
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
connectors/class-connector-mainwp-backups.php (2)
273-279: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winRetry after an active lock owner fails.
When
add_option()finds an unexpired lock, this method returns immediately. If the lock owner then receivesfalseornullfromConnector::log()and releases the lock, this delivery is lost unless the producer sends another callback.Add a bounded retry after the lock disappears. Re-acquire the lock and run
fingerprint_exists()again before logging.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@connectors/class-connector-mainwp-backups.php` around lines 273 - 279, Update the lock-handling flow around add_option() in the relevant connector method so that, when an initially active lock disappears, it performs one bounded retry: re-acquire the lock, re-run fingerprint_exists(), and continue to Connector::log() only if appropriate. Preserve the existing immediate failure behavior for malformed or still-unexpired locks, and avoid unbounded retries.
356-369: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winHandle lookup errors separately from missing fingerprints.
$wpdb->get_var()returnsnullfor both cases. Check$wpdb->last_errorimmediately after the query. ReturnWP_Erroron failure andnull !== $record_idfor a matching record. Inlog_backup(), release the lock and returnfalsewhen the lookup returnsWP_Error. Inwas_fingerprint_logged(), returntrue === self::fingerprint_exists( $fingerprint )so an error cannot advance the UpdraftPlus timestamp.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@connectors/class-connector-mainwp-backups.php` around lines 356 - 369, Update the fingerprint lookup method around $wpdb->get_var() to inspect $wpdb->last_error immediately, return a WP_Error for query failures, and use null !== $record_id to distinguish a match from a missing record. In log_backup(), release the lock and return false when fingerprint_exists() returns WP_Error; in was_fingerprint_logged(), return true === self::fingerprint_exists( $fingerprint ) so lookup errors cannot advance the timestamp.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@connectors/class-connector-mainwp-backups.php`:
- Around line 273-279: Update the lock-handling flow around add_option() in the
relevant connector method so that, when an initially active lock disappears, it
performs one bounded retry: re-acquire the lock, re-run fingerprint_exists(),
and continue to Connector::log() only if appropriate. Preserve the existing
immediate failure behavior for malformed or still-unexpired locks, and avoid
unbounded retries.
- Around line 356-369: Update the fingerprint lookup method around
$wpdb->get_var() to inspect $wpdb->last_error immediately, return a WP_Error for
query failures, and use null !== $record_id to distinguish a match from a
missing record. In log_backup(), release the lock and return false when
fingerprint_exists() returns WP_Error; in was_fingerprint_logged(), return true
=== self::fingerprint_exists( $fingerprint ) so lookup errors cannot advance the
timestamp.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 15b455f8-0546-48ff-ba0e-911a02475fc7
📒 Files selected for processing (1)
connectors/class-connector-mainwp-backups.php
…and cleanup for expired locks
|



Summary by CodeRabbit
New Features
Bug Fixes