get_campaigns_with_ads( $space_id ); if ( empty( $campaigns_data ) ) { return 0; } $count = 0; foreach ( $campaigns_data as $entry ) { $count += count( $entry['ads'] ); } return $count; } public function bust_campaigns( int $space_id ): void { wp_cache_delete( "campaigns_ads_{$space_id}", self::GROUP ); delete_transient( "adfuz_c_{$space_id}" ); } public function bust_campaigns_by_campaign( int $campaign_id ): void { $space_ids = DB::get( TableName::ADFUZ_CAMPAIGN_AD_SPACES() ) ->where( 'campaign_id', $campaign_id ) ->select( 'ad_space_id' ) ->get(); $space_ids = array_column( $space_ids, 'ad_space_id' ); foreach ( $space_ids as $space_id ) { $this->bust_campaigns( (int) $space_id ); } } // ------------------------------------------------------------------------- // Single Ad — now via Ads::findActive() // ------------------------------------------------------------------------- public function get_ad( int $id ): ?array { $cache_key = "ad_{$id}"; $cached = wp_cache_get( $cache_key, self::GROUP ); if ( false !== $cached ) { return $cached ?: null; } $row = Ads::findActive( $id ); $value = $row ?: false; // keep as array, not (object) wp_cache_set( $cache_key, $value, self::GROUP ); return $value ?: null; } // ------------------------------------------------------------------------- // Sequential Pointer — unchanged // ------------------------------------------------------------------------- public function get_sequential_pointer( int $space_id ): int { return (int) get_transient( "adfuz_seq_{$space_id}" ); } public function advance_sequential_pointer( int $space_id ): void { $current = $this->get_sequential_pointer( $space_id ); set_transient( "adfuz_seq_{$space_id}", $current + 1, DAY_IN_SECONDS ); } }