Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassScanner - Fix guard for preboot cache scenario #24480

Merged
merged 1 commit into from
Sep 9, 2022

Conversation

totten
Copy link
Member

@totten totten commented Sep 8, 2022

Overview

Wanted to inspect how class-scanner caches were behaving during test-runs. So I applied this hack (HitOrMiss reporting - 02106e8) and then ran some tests, eg

CIVICRM_UF=UnitTests phpunit8 tests/phpunit/CRM/Case/WorkflowMessage/CaseActivityTest.php

It showed an extremely high number of non-caching calls. You can see in the HitOrMiss report below. The patch should improve caching.

Before

All attempts to instantiate the ClassScanner::cache('index') cause it to create dummy/one-off placeholders, as per

if (empty($_DB_DATAOBJECT['CONFIG'])) {
  return new \CRM_Utils_Cache_ArrayCache([]);
}

For CaseActivityTest, it does this 13 times.

OK (3 tests, 38 assertions)
HitOrMiss: {
    "ClassScanner::cache(index) => Early usage": 13,
    "ClassScanner::cache(structure) => New arraycache": 1
}

After

Attempts to instantiate the ClassScanner::cache('index') can create a real cache, as per:

static::$caches[$name] = \CRM_Utils_Cache::create([
  'name' => 'classes',
  'type' => ['*memory*', 'SqlGroup', 'ArrayCache'],
  'fastArray' => TRUE,
]);

For CaseActivityTest, it does this -- and it only runs 1 time.

OK (3 tests, 38 assertions)
HitOrMiss: {
    "ClassScanner::cache(index) => create(...)": 1,
    "ClassScanner::cache(structure) => New arraycache": 2
}

I wanted to inspect how caches were getting setup during test-runs.  So I applied
this hack civicrm@02106e8
and then ran some tests, eg

```
CIVICRM_UF=UnitTests phpunit8 tests/phpunit/CRM/Case/WorkflowMessage/CaseActivityTest.php
```

You can see the change in the HitOrMiss report (displayed after the test).

Before
======

```
OK (3 tests, 38 assertions)
HitOrMiss: {
    "ClassScanner::cache(index) => Early usage": 13,
    "ClassScanner::cache(structure) => New arraycache": 1
}
```

After
=====

```
OK (3 tests, 38 assertions)
HitOrMiss: {
    "ClassScanner::cache(index) => create(...)": 1,
    "ClassScanner::cache(structure) => New arraycache": 2
}
```
@civibot
Copy link

civibot bot commented Sep 8, 2022

(Standard links)

@civibot civibot bot added the master label Sep 8, 2022
@demeritcowboy
Copy link
Contributor

This seems clearly correct even though it wasn't what we were looking for.

@demeritcowboy demeritcowboy merged commit a26fb03 into civicrm:master Sep 9, 2022
@totten totten deleted the master-global branch September 9, 2022 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants