Skip to content

Commit 84ef834

Browse files
committed
merge #778
1 parent d295ecd commit 84ef834

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

agent/fw_wordpress.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@ static void nr_wordpress_call_user_func_array(zend_function* func,
358358
nr_php_wrap_callable(func, nr_wordpress_wrap_hook TSRMLS_CC);
359359
}
360360

361+
static void free_tag(void* tag) {
362+
nr_free(tag);
363+
}
364+
361365
/*
362366
* Some plugins generate transient tag names. We can detect these by checking
363367
* the substrings returned from our regex rule. If the tag is transient, we
@@ -366,8 +370,7 @@ static void nr_wordpress_call_user_func_array(zend_function* func,
366370
* Example: (old) add_option__transient_timeout_twccr_382402301f44c883bc0137_cat
367371
* (new) add_option__transient_timeout_twccr_*_cat
368372
*/
369-
static char* nr_wordpress_clean_tag(const zval* tag TSRMLS_DC) {
370-
char* orig_tag = NULL;
373+
static char* nr_wordpress_clean_tag(const zval* tag) {
371374
char* clean_tag = NULL;
372375
nr_regex_t* regex = NULL;
373376
nr_regex_substrings_t* ss = NULL;
@@ -381,8 +384,16 @@ static char* nr_wordpress_clean_tag(const zval* tag TSRMLS_DC) {
381384
return NULL;
382385
}
383386

384-
orig_tag = nr_strndup(Z_STRVAL_P(tag), Z_STRLEN_P(tag));
385-
ss = nr_regex_match_capture(regex, orig_tag, nr_strlen(orig_tag));
387+
if (NULL == NRPRG(wordpress_clean_tag_cache)) {
388+
NRPRG(wordpress_clean_tag_cache) = nr_hashmap_create(free_tag);
389+
}
390+
391+
if (nr_hashmap_get_into(NRPRG(wordpress_clean_tag_cache), Z_STRVAL_P(tag),
392+
Z_STRLEN_P(tag), (void**)&clean_tag)) {
393+
return clean_tag;
394+
}
395+
396+
ss = nr_regex_match_capture(regex, Z_STRVAL_P(tag), Z_STRLEN_P(tag));
386397
clean_tag = nr_regex_substrings_get(ss, 5);
387398

388399
/*
@@ -403,7 +414,9 @@ static char* nr_wordpress_clean_tag(const zval* tag TSRMLS_DC) {
403414
}
404415

405416
nr_regex_substrings_destroy(&ss);
406-
nr_free(orig_tag);
417+
418+
nr_hashmap_set(NRPRG(wordpress_clean_tag_cache), Z_STRVAL_P(tag),
419+
Z_STRLEN_P(tag), clean_tag);
407420

408421
return clean_tag;
409422
}
@@ -429,9 +442,8 @@ NR_PHP_WRAPPER(nr_wordpress_exec_handle_tag) {
429442

430443
NRPRG(check_cufa) = true;
431444

432-
NRPRG(wordpress_tag) = nr_wordpress_clean_tag(tag TSRMLS_CC);
445+
NRPRG(wordpress_tag) = nr_wordpress_clean_tag(tag);
433446
NR_PHP_WRAPPER_CALL;
434-
nr_free(NRPRG(wordpress_tag));
435447
NRPRG(wordpress_tag) = old_tag;
436448
if (NULL == NRPRG(wordpress_tag)) {
437449
NRPRG(check_cufa) = false;
@@ -517,10 +529,8 @@ NR_PHP_WRAPPER(nr_wordpress_apply_filters) {
517529

518530
NRPRG(check_cufa) = true;
519531

520-
NRPRG(wordpress_tag) = nr_wordpress_clean_tag(tag TSRMLS_CC);
521-
532+
NRPRG(wordpress_tag) = nr_wordpress_clean_tag(tag);
522533
NR_PHP_WRAPPER_CALL;
523-
nr_free(NRPRG(wordpress_tag));
524534
NRPRG(wordpress_tag) = old_tag;
525535
if (NULL == NRPRG(wordpress_tag)) {
526536
NRPRG(check_cufa) = false;

agent/php_newrelic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ nr_matcher_t* wordpress_theme_matcher; /* Matcher for theme filenames */
389389
nr_matcher_t* wordpress_core_matcher; /* Matcher for plugin filenames */
390390
nr_hashmap_t* wordpress_file_metadata; /* Metadata for plugin and theme names
391391
given a filename */
392+
nr_hashmap_t* wordpress_clean_tag_cache; /* Cached clean tags */
392393

393394
char* doctrine_dql; /* The current Doctrine DQL. Only non-NULL while a Doctrine
394395
object is on the stack. */

agent/php_rshutdown.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ int nr_php_post_deactivate(void) {
100100
nr_matcher_destroy(&NRPRG(wordpress_core_matcher));
101101
nr_matcher_destroy(&NRPRG(wordpress_theme_matcher));
102102
nr_hashmap_destroy(&NRPRG(wordpress_file_metadata));
103+
nr_hashmap_destroy(&NRPRG(wordpress_clean_tag_cache));
103104

104105
nr_free(NRPRG(mysql_last_conn));
105106
nr_free(NRPRG(pgsql_last_conn));

0 commit comments

Comments
 (0)