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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 );
|
||||
|
||||
@@ -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__ );
|
||||
|
||||
Reference in New Issue
Block a user