From 74301682fee5068575a3bc04215e8529abd54b19 Mon Sep 17 00:00:00 2001 From: peptiderepo Date: Tue, 14 Apr 2026 01:23:46 +0700 Subject: [PATCH] fix: bypass daily cap for admin-initiated AJAX enrichment (v4.4.1) The daily generation cap is designed for automated cron-based processes. When an admin explicitly clicks Re-enrich, they accept the cost. The AJAX enrichment is already rate-limited by a 2-second polling interval and still respects the monthly budget check in generate_peptide_content(). Co-Authored-By: Claude Opus 4.6 --- includes/class-psa-batch-enrichment.php | 24 ++++-------------------- peptide-search-ai.php | 4 ++-- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/includes/class-psa-batch-enrichment.php b/includes/class-psa-batch-enrichment.php index 688a036..32c4189 100755 --- a/includes/class-psa-batch-enrichment.php +++ b/includes/class-psa-batch-enrichment.php @@ -68,22 +68,10 @@ class PSA_Batch_Enrichment { check_ajax_referer( 'psa_batch_enrich', '_nonce' ); - // Respect daily generation cap. - $daily_key = 'psa_daily_gen_' . gmdate( 'Y-m-d' ); - $daily_count = (int) get_transient( $daily_key ); - if ( $daily_count >= PSA_Config::DAILY_GENERATION_CAP ) { - wp_send_json_success( - array( - 'status' => 'cap_reached', - 'message' => sprintf( - 'Daily generation cap reached (%d/%d). Try again tomorrow.', - $daily_count, - PSA_Config::DAILY_GENERATION_CAP - ), - 'remaining' => count( self::get_unenriched_ids() ), - ) - ); - } + // Admin-initiated batch enrichment intentionally bypasses the daily cap. + // The cap exists to prevent runaway cron-based costs; AJAX enrichment is + // explicit, authenticated, rate-limited by the 2-second JS polling interval, + // and still respects the monthly budget check inside generate_peptide_content(). $ids = self::get_unenriched_ids(); if ( empty( $ids ) ) { @@ -117,10 +105,6 @@ class PSA_Batch_Enrichment { // Call the generator directly (synchronous — no cron dependency). PSA_AI_Generator::background_generate( $post_id, $peptide_name ); - // Bump daily counter. - $daily_count = (int) get_transient( $daily_key ); - set_transient( $daily_key, $daily_count + 1, DAY_IN_SECONDS ); - // Check outcome: did generation succeed? $error = get_post_meta( $post_id, 'psa_generation_error', true ); $refreshed_post = get_post( $post_id ); diff --git a/peptide-search-ai.php b/peptide-search-ai.php index f8d85f7..4c1ddce 100755 --- a/peptide-search-ai.php +++ b/peptide-search-ai.php @@ -3,7 +3,7 @@ * Plugin Name: Peptide Search AI * Plugin URI: https://example.com/peptide-search-ai * Description: Searchable peptide database with AI-powered auto-population and browsable directory. - * Version: 4.4.0 + * Version: 4.4.1 * Author: Terence * License: GPL v2 or later * Text Domain: peptide-search-ai @@ -15,7 +15,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -define( 'PSA_VERSION', '4.4.0' ); +define( 'PSA_VERSION', '4.4.1' ); define( 'PSA_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); define( 'PSA_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'PSA_PLUGIN_FILE', __FILE__ );