Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
simple_sitemap
Commits
2c8224c2
Commit
2c8224c2
authored
Sep 21, 2018
by
Pawel G
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#3001470
by gbyte.co: Remove caching as now all sitemap content is stored in database
parent
54765021
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
52 deletions
+6
-52
src/Controller/SimplesitemapController.php
src/Controller/SimplesitemapController.php
+3
-21
src/Plugin/simple_sitemap/SitemapGenerator/SitemapGeneratorBase.php
.../simple_sitemap/SitemapGenerator/SitemapGeneratorBase.php
+3
-31
No files found.
src/Controller/SimplesitemapController.php
View file @
2c8224c2
...
...
@@ -5,10 +5,8 @@ namespace Drupal\simple_sitemap\Controller;
use
Drupal\Core\Controller\ControllerBase
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\HttpFoundation\Response
;
use
Drupal\Core\Cache\CacheableResponse
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
Drupal\simple_sitemap
\
Simplesitemap
;
use
Drupal\Core\PageCache\ResponsePolicy\KillSwitch
;
use
Symfony\Component\HttpFoundation\Request
;
use
Drupal\simple_sitemap
\
SimplesitemapManager
;
...
...
@@ -23,19 +21,12 @@ class SimplesitemapController extends ControllerBase {
*/
protected
$generator
;
/**
* @var \Drupal\Core\PageCache\ResponsePolicy\KillSwitch
*/
protected
$cacheKillSwitch
;
/**
* SimplesitemapController constructor.
* @param \Drupal\simple_sitemap\Simplesitemap $generator
* @param \Drupal\Core\PageCache\ResponsePolicy\KillSwitch $cache_kill_switch
*/
public
function
__construct
(
Simplesitemap
$generator
,
KillSwitch
$cache_kill_switch
)
{
public
function
__construct
(
Simplesitemap
$generator
)
{
$this
->
generator
=
$generator
;
$this
->
cacheKillSwitch
=
$cache_kill_switch
;
}
/**
...
...
@@ -43,8 +34,7 @@ class SimplesitemapController extends ControllerBase {
*/
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'simple_sitemap.generator'
),
$container
->
get
(
'page_cache_kill_switch'
)
$container
->
get
(
'simple_sitemap.generator'
)
);
}
...
...
@@ -73,20 +63,12 @@ class SimplesitemapController extends ControllerBase {
$output
=
$this
->
generator
->
getSitemap
(
$variant
,
$request
->
query
->
getInt
(
'page'
));
if
(
!
$output
)
{
$this
->
cacheKillSwitch
->
trigger
();
throw
new
NotFoundHttpException
();
}
$
re
sponse
=
new
Cacheable
Response
(
$output
,
Response
::
HTTP_OK
,
[
re
turn
new
Response
(
$output
,
Response
::
HTTP_OK
,
[
'content-type'
=>
'application/xml'
,
'X-Robots-Tag'
=>
'noindex'
,
// Tell search engines not to index the sitemap itself.
]);
// Cache output.
$response
->
getCacheableMetadata
()
->
addCacheTags
([
"simple_sitemap:
$variant
"
])
->
addCacheContexts
([
'url.query_args'
]);
return
$response
;
}
}
src/Plugin/simple_sitemap/SitemapGenerator/SitemapGeneratorBase.php
View file @
2c8224c2
...
...
@@ -191,57 +191,29 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
}
public
static
function
removeSitemapVariant
(
$variant
=
NULL
,
$mode
=
'all'
)
{
$connection
=
\
Drupal
::
database
();
$delete_query
=
$connection
->
delete
(
'simple_sitemap'
);
$delete_query
=
\
Drupal
::
database
()
->
delete
(
'simple_sitemap'
);
switch
(
$mode
)
{
case
'published'
:
$status
=
1
;
$
delete_query
->
condition
(
'
status
'
,
1
)
;
break
;
case
'unpublished'
:
$status
=
0
;
$
delete_query
->
condition
(
'
status
'
,
0
)
;
break
;
case
'all'
:
$status
=
NULL
;
break
;
default
:
//todo: throw error
}
if
(
NULL
!==
$status
)
{
$delete_query
->
condition
(
'status'
,
$status
);
}
if
(
NULL
!==
$variant
)
{
$delete_query
->
condition
(
'type'
,
$variant
);
}
elseif
(
$status
!==
0
)
{
$variant
=
$connection
->
query
(
'SELECT DISTINCT type from {simple_sitemap} WHERE status = :status'
,
[
':status'
=>
1
])
->
fetchCol
();
}
$delete_query
->
execute
();
if
(
NULL
!==
$variant
)
{
self
::
invalidateCache
(
$variant
);
}
}
/**
* @param string|array $variants
*/
protected
static
function
invalidateCache
(
$variants
)
{
$variants
=
is_array
(
$variants
)
?
$variants
:
[
$variants
];
$tags
=
array_map
(
function
(
$variant
)
{
return
'simple_sitemap:'
.
$variant
;
},
$variants
);
Cache
::
invalidateTags
(
$tags
);
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment