Skip to content

Commit 942286a

Browse files
authored
Fixed #301 compile cache warmup on initialization
Fix compile cache warmup on init cache
2 parents e6b1992 + 5ca4636 commit 942286a

File tree

11 files changed

+61
-31
lines changed

11 files changed

+61
-31
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ matrix:
3434
- php: nightly
3535
env: COMPOSER_UPDATE_FLAGS=--ignore-platform-reqs
3636
allow_failures:
37-
- php: 7.2
38-
env: SYMFONY_VERSION=4.1.* DEPENDENCIES=dev
3937
- php: nightly
4038
env: COMPOSER_UPDATE_FLAGS=--ignore-platform-reqs
4139

CacheWarmer/CompileCacheWarmer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public function isOptional()
2828
*/
2929
public function warmUp($cacheDir)
3030
{
31+
// use warm up cache dir if type generator cache dir not already explicitly declare
32+
$baseCacheDir = $this->typeGenerator->getBaseCacheDir();
33+
if (null === $this->typeGenerator->getCacheDir(false)) {
34+
$this->typeGenerator->setBaseCacheDir($cacheDir);
35+
}
3136
$this->typeGenerator->compile(TypeGenerator::MODE_WRITE | TypeGenerator::MODE_OVERRIDE);
37+
$this->typeGenerator->setBaseCacheDir($baseCacheDir);
3238
}
3339
}

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function getConfigTreeBuilder()
4646
->scalarNode('internal_error_message')->defaultNull()->end()
4747
->variableNode('default_resolver')->defaultValue([Resolver::class, 'defaultResolveFn'])->end()
4848
->scalarNode('class_namespace')->defaultValue('Overblog\\GraphQLBundle\\__DEFINITIONS__')->end()
49-
->scalarNode('cache_dir')->defaultValue($this->cacheDir.'/overblog/graphql-bundle/__definitions__')->end()
49+
->scalarNode('cache_dir')->defaultNull()->end()
5050
->booleanNode('use_classloader_listener')->defaultTrue()->end()
5151
->booleanNode('auto_compile')->defaultTrue()->end()
5252
->booleanNode('show_debug_info')->defaultFalse()->end()

Generator/TypeGenerator.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,52 @@ class TypeGenerator extends BaseTypeGenerator
2222

2323
private $useClassMap = true;
2424

25+
private $baseCacheDir;
26+
2527
private static $classMapLoaded = false;
2628

27-
public function __construct($classNamespace, array $skeletonDirs, $cacheDir, callable $defaultResolver, array $configs, $useClassMap = true)
29+
public function __construct($classNamespace, array $skeletonDirs, $cacheDir, callable $defaultResolver, array $configs, $useClassMap = true, $baseCacheDir = null)
2830
{
2931
$this->setCacheDir($cacheDir);
3032
$this->defaultResolver = $defaultResolver;
3133
$this->configs = $this->processConfigs($configs);
3234
$this->useClassMap = $useClassMap;
35+
$this->baseCacheDir = $baseCacheDir;
36+
3337
parent::__construct($classNamespace, $skeletonDirs);
3438
}
3539

3640
/**
37-
* @return string
41+
* @return string|null
42+
*/
43+
public function getBaseCacheDir()
44+
{
45+
return $this->baseCacheDir;
46+
}
47+
48+
/**
49+
* @param string|null $baseCacheDir
3850
*/
39-
public function getCacheDir()
51+
public function setBaseCacheDir($baseCacheDir)
4052
{
41-
return $this->cacheDir;
53+
$this->baseCacheDir = $baseCacheDir;
54+
}
55+
56+
/**
57+
* @return string|null
58+
*/
59+
public function getCacheDir(/*bool $useDefault = true*/)
60+
{
61+
$useDefault = func_num_args() > 0 ? func_get_arg(0) : true;
62+
if ($useDefault) {
63+
return $this->cacheDir ?: $this->baseCacheDir.'/overblog/graphql-bundle/__definitions__';
64+
} else {
65+
return $this->cacheDir;
66+
}
4267
}
4368

4469
/**
45-
* @param string $cacheDir
70+
* @param string|null $cacheDir
4671
*
4772
* @return $this
4873
*/

Resources/config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ services:
9898
- "%overblog_graphql.default_resolver%"
9999
- "%overblog_graphql_types.config%"
100100
- "%overblog_graphql.use_classloader_listener%"
101+
- "%kernel.cache_dir%"
101102
calls:
102103
- ["addUseStatement", ["Symfony\\Component\\DependencyInjection\\ContainerInterface"]]
103104
- ["addUseStatement", ["Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface"]]

Tests/Functional/App/config/access/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
imports:
22
- { resource: ../config.yml }
3-
- { resource: ../security.yml }
43
- { resource: ../connection/services.yml }
54
- { resource: ../mutation/services.yml }
65

Tests/Functional/App/config/config.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@ framework:
88
profiler:
99
enabled: false
1010

11+
security:
12+
providers:
13+
in_memory:
14+
memory:
15+
users:
16+
ryan:
17+
password: 123
18+
roles: 'ROLE_USER'
19+
admin:
20+
password: 123
21+
roles: 'ROLE_ADMIN'
22+
encoders:
23+
Symfony\Component\Security\Core\User\User: plaintext
24+
firewalls:
25+
graph:
26+
pattern: ^/
27+
http_basic: ~
28+
stateless: true
29+
anonymous: true
30+
31+
1132
overblog_graphql:
1233
definitions:
1334
config_validation: true

Tests/Functional/App/config/public/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
imports:
22
- { resource: ../config.yml }
3-
- { resource: ../security.yml }
43

54
overblog_graphql:
65
definitions:

Tests/Functional/App/config/queryComplexityEnv/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ imports:
33
- { resource: ../connection/services.yml }
44

55
parameters:
6-
env(GRAPHQL_QUERY_MAX_COMPLEXITY): 10
6+
env(GRAPHQL_QUERY_MAX_COMPLEXITY): "10"
77

88
overblog_graphql:
99
security:

Tests/Functional/App/config/queryMaxDepthEnv/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ imports:
33
- { resource: ../connection/services.yml }
44

55
parameters:
6-
env(GRAPHQL_QUERY_MAX_DEPTH): 3
6+
env(GRAPHQL_QUERY_MAX_DEPTH): "3"
77

88
overblog_graphql:
99
security:

0 commit comments

Comments
 (0)