Skip to content

Commit cde8213

Browse files
mfulblavarou
authored andcommitted
Instead of copying cache just reference it as a const data source
1 parent 6b914aa commit cde8213

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

agent/php_txn.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,10 +1156,15 @@ nr_status_t nr_php_txn_begin(const char* appnames,
11561156
&& (NULL != NR_PHP_PROCESS_GLOBALS(composer_php_packages))) {
11571157
nrl_verbosedebug(NRL_FRAMEWORK,
11581158
"composer packages already detected, using cached values");
1159+
#if 0
11591160
nr_php_packages_destroy(&NRPRG(txn)->php_packages);
11601161
NRPRG(txn)->php_packages
11611162
= nr_php_packages_clone(NR_PHP_PROCESS_GLOBALS(composer_php_packages));
11621163
nrl_verbosedebug(NRL_FRAMEWORK, "composer packages cloned from cache");
1164+
#else
1165+
nr_php_packages_set_known(NRPRG(txn)->php_packages,
1166+
NR_PHP_PROCESS_GLOBALS(composer_php_packages));
1167+
#endif
11631168
}
11641169

11651170
return NR_SUCCESS;

axiom/nr_php_packages.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ static inline const char* nr_php_package_source_priority_to_string(const nr_php_
3636
}
3737
}
3838

39+
void nr_php_packages_set_known(nr_php_packages_t* pkgs,
40+
const nr_hashmap_t* known) {
41+
if (NULL == pkgs || NULL == known) {
42+
return;
43+
}
44+
45+
pkgs->known_packages = known;
46+
}
47+
3948
nr_php_package_t* nr_php_package_create_with_source(
4049
const char* name,
4150
const char* version,
@@ -154,6 +163,20 @@ nr_php_package_t* nr_php_packages_add_package(nr_php_packages_t* h,
154163
return NULL;
155164
}
156165

166+
// if package is in known packages then ignore
167+
168+
package = (nr_php_package_t*)nr_hashmap_get(
169+
h->known_packages, p->package_name, nr_strlen(p->package_name));
170+
if (NULL != package) {
171+
if (package->source_priority <= p->source_priority
172+
&& 0 != nr_strcmp(package->package_version, p->package_version)) {
173+
nr_free(package->package_version);
174+
package->package_version = nr_strdup(p->package_version);
175+
}
176+
nr_php_package_destroy(p);
177+
return NULL;
178+
}
179+
157180
// If package with the same key already exists, we will check if the value is
158181
// different. If it is different, then we will update the value of the package
159182
package = (nr_php_package_t*)nr_hashmap_get(h->data, p->package_name,

axiom/nr_php_packages.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ typedef struct _nr_php_package_t {
2828

2929
typedef struct _nr_php_packages_t {
3030
nr_hashmap_t* data;
31+
const nr_hashmap_t* known_packages;
3132
} nr_php_packages_t;
3233

3334
typedef void(nr_php_packages_iter_t)(void* value,
3435
const char* name,
3536
size_t name_len,
3637
void* user_data);
3738

39+
void nr_php_packages_set_known(nr_php_packages_t* pkgs,
40+
const nr_hashmap_t* known);
41+
3842
/*
3943
* Purpose : Create a new php package with desired source priority. If the name is null, then no package will
4044
* be created. If the version is null (version = NULL), then

0 commit comments

Comments
 (0)