Skip to content
Snippets Groups Projects
Commit 1a9ec5d7 authored by Brian Canini's avatar Brian Canini
Browse files

Merge branch 'simple_sitemap' into module-updates-rc

parents e1a14ef7 80527b44
No related branches found
No related tags found
No related merge requests found
Showing
with 317 additions and 117 deletions
......@@ -7920,17 +7920,17 @@
},
{
"name": "drupal/simple_sitemap",
"version": "3.9.0",
"version": "3.10.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/simple_sitemap.git",
"reference": "8.x-3.9"
"reference": "8.x-3.10"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/simple_sitemap-8.x-3.9.zip",
"reference": "8.x-3.9",
"shasum": "4892f2196e35e6fc67f3da8748825815efe6462d"
"url": "https://ftp.drupal.org/files/projects/simple_sitemap-8.x-3.10.zip",
"reference": "8.x-3.10",
"shasum": "4836e5d5bae0b4348406c832f81eabfaf16483e3"
},
"require": {
"drupal/core": "^8 || ^9",
......@@ -7939,8 +7939,8 @@
"type": "drupal-module",
"extra": {
"drupal": {
"version": "8.x-3.9",
"datestamp": "1614984547",
"version": "8.x-3.10",
"datestamp": "1617840662",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......
......@@ -1843,12 +1843,12 @@ class InstalledVersions
),
'drupal/simple_sitemap' =>
array (
'pretty_version' => '3.9.0',
'version' => '3.9.0.0',
'pretty_version' => '3.10.0',
'version' => '3.10.0.0',
'aliases' =>
array (
),
'reference' => '8.x-3.9',
'reference' => '8.x-3.10',
),
'drupal/simplesamlphp_auth' =>
array (
......
......@@ -8199,18 +8199,18 @@
},
{
"name": "drupal/simple_sitemap",
"version": "3.9.0",
"version_normalized": "3.9.0.0",
"version": "3.10.0",
"version_normalized": "3.10.0.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/simple_sitemap.git",
"reference": "8.x-3.9"
"reference": "8.x-3.10"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/simple_sitemap-8.x-3.9.zip",
"reference": "8.x-3.9",
"shasum": "4892f2196e35e6fc67f3da8748825815efe6462d"
"url": "https://ftp.drupal.org/files/projects/simple_sitemap-8.x-3.10.zip",
"reference": "8.x-3.10",
"shasum": "4836e5d5bae0b4348406c832f81eabfaf16483e3"
},
"require": {
"drupal/core": "^8 || ^9",
......@@ -8219,8 +8219,8 @@
"type": "drupal-module",
"extra": {
"drupal": {
"version": "8.x-3.9",
"datestamp": "1614984547",
"version": "8.x-3.10",
"datestamp": "1617840662",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......
......@@ -1819,12 +1819,12 @@
),
'drupal/simple_sitemap' =>
array (
'pretty_version' => '3.9.0',
'version' => '3.9.0.0',
'pretty_version' => '3.10.0',
'version' => '3.10.0.0',
'aliases' =>
array (
),
'reference' => '8.x-3.9',
'reference' => '8.x-3.10',
),
'drupal/simplesamlphp_auth' =>
array (
......
......@@ -4,6 +4,7 @@
* Installation
* Configuration
* Usage
* Debugging
* Extending the module
* How Can You Contribute?
* Maintainers
......@@ -44,6 +45,12 @@ for instructions on how to install or update Drupal modules.
The module permission 'administer sitemap settings' can be configured under
/admin/people/permissions.
### VARIANTS ###
It is possible to have several sitemap instances of different sitemap types with
specific links accessible under certain URLs. These sitemap variants can be
configured under admin/config/search/simplesitemap/variants.
### ENTITIES ###
Initially only the home page is indexed in the default sitemap variant. To
......@@ -82,33 +89,42 @@ checks for links added through the module's hooks (see below).
### VIEWS ###
To index views, enable the included, optional module Simple XML Sitemap (Views)
(simple_sitemap_views). Simple views as well as views with arguments can be
indexed on the view edit page. For views with arguments, links to all view
variants will be included in the sitemap.
(simple_sitemap_views).
Simple views as well as views with arguments can be indexed on the view edit
page. For views with arguments, links to all view variants will be included in
the sitemap.
### CUSTOM LINKS ###
To include custom links into a sitemap, visit
/admin/config/search/simplesitemap/custom.
### SETTINGS ###
### AUTOMATIC SUBMISSION ###
The settings page can be found under admin/config/search/simplesitemap.
Here the module can be configured and the sitemaps manually regenerated.
It is possible to have the module automatically submit specific sitemap
variants to search engines. Google and Bing are preconfigured.
#### VARIANTS ####
This functionality is available through the included simple_sitemap_engines
submodule. After enabling this module, go to
admin/config/search/simplesitemap/engines/settings to set it up.
It is possible to have several sitemap instances of different sitemap types with
specific links accessible under certain URLs. These sitemap variants can be
configured under admin/config/search/simplesitemap/variants.
### PERFORMANCE ###
#### AUTOMATIC SUBMISSION ####
The module can be tuned via UI for a vast improvement in generation speeds on
huge sites. To speed up generation, go to
admin/config/search/simplesitemap/engines/settings and increase
'Entities per queue item' and 'Sitemap generation max duration'.
It is possible to have the module automatically submit specific sitemap
variants to search engines. Google and Bing are preconfigured. This
functionality is available through the included simple_sitemap_engines
submodule. After enabling this module, go to
admin/config/search/simplesitemap/engines/settings to set it up.
Further things that can be tweaked are unchecking 'Exclude duplicate links' and
increasing 'Maximum links in a sitemap'.
These settings will increase the demand for PHP execution time and memory, so
please make sure to test the sitemap generation behaviour. See 'PERFORMANCE TEST'.
### OTHER SETTINGS ###
Other settings can be found under admin/config/search/simplesitemap/settings.
## USAGE ##
......@@ -136,6 +152,21 @@ Generation of hundreds of thousands of links can take time. Each variant gets
published as soon as all of its links have been generated. The previous version
of the sitemap variant is accessible during the generation process.
## Debugging ##
### PERFORMANCE TEST ###
The module includes a script that can be used to test the sitemap generation
performance.
Run `drush scr --uri http://example.com modules/simple_sitemap/tests/scripts/performance_test.php`
on your production environment to calculate generation speed and the amount of
queries performed.
If testing on a non-production environment, you can generate dummy content prior
to generation:
`drush scr --uri http://example.com modules/simple_sitemap/tests/scripts/performance_test.php -- generate 500`
## EXTENDING THE MODULE ##
### API ###
......
......@@ -13,3 +13,4 @@ enabled_entity_types:
- 'node'
- 'taxonomy_term'
- 'menu_link_content'
entities_per_queue_item: 50
......@@ -44,6 +44,9 @@ simple_sitemap.settings:
type: sequence
sequence:
type: string
entities_per_queue_item:
label: 'Entities per queue item'
type: integer
simple_sitemap.bundle_settings.*.*.*:
label: 'Entity bundle settings'
......
......@@ -8,7 +8,7 @@ core_version_requirement: ^8 || ^9
dependencies:
- simple_sitemap:simple_sitemap
# Information added by Drupal.org packaging script on 2021-03-05
version: '8.x-3.9'
# Information added by Drupal.org packaging script on 2021-04-07
version: '8.x-3.10'
project: 'simple_sitemap'
datestamp: 1614984549
datestamp: 1617833759
......@@ -9,7 +9,7 @@ dependencies:
- simple_sitemap:simple_sitemap
- drupal:views
# Information added by Drupal.org packaging script on 2021-03-05
version: '8.x-3.9'
# Information added by Drupal.org packaging script on 2021-04-07
version: '8.x-3.10'
project: 'simple_sitemap'
datestamp: 1614984549
datestamp: 1617833759
......@@ -64,8 +64,6 @@ function simple_sitemap_views_schema() {
],
'primary key' => ['id'],
'indexes' => [
'view' => ['view_id'],
'display' => ['view_id', 'display_id'],
'arguments_ids' => ['view_id', 'display_id', 'arguments_ids'],
],
];
......@@ -108,3 +106,12 @@ function simple_sitemap_views_update_8301() {
}
}
}
/**
* Remove unnecessary indexes.
*/
function simple_sitemap_views_update_8302() {
$schema = \Drupal::database()->schema();
$schema->dropIndex('simple_sitemap_views', 'view');
$schema->dropIndex('simple_sitemap_views', 'display');
}
......@@ -7,7 +7,7 @@ core_version_requirement: ^8 || ^9
dependencies:
- simple_sitemap:simple_sitemap_views
# Information added by Drupal.org packaging script on 2021-03-05
version: '8.x-3.9'
# Information added by Drupal.org packaging script on 2021-04-07
version: '8.x-3.10'
project: 'simple_sitemap'
datestamp: 1614984549
datestamp: 1617833759
......@@ -6,7 +6,7 @@ package: SEO
core: 8.x
core_version_requirement: ^8 || ^9
# Information added by Drupal.org packaging script on 2021-03-05
version: '8.x-3.9'
# Information added by Drupal.org packaging script on 2021-04-07
version: '8.x-3.10'
project: 'simple_sitemap'
datestamp: 1614984549
datestamp: 1617833759
......@@ -5,6 +5,8 @@
* Module install and update procedures.
*/
use Drupal\Core\Database\Database;
/**
* Implements hook_requirements().
*
......@@ -129,8 +131,18 @@ function simple_sitemap_schema() {
'unsigned' => TRUE,
'default' => 0,
],
'link_count' => [
'description' => 'The number of links in the sitemap.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
],
],
'primary key' => ['id'],
'indexes' => [
'type_status_delta' => ['type', 'status', 'delta'],
],
];
$schema['simple_sitemap_entity_overrides'] = [
......@@ -166,6 +178,9 @@ function simple_sitemap_schema() {
],
],
'primary key' => ['id'],
'indexes' => [
'entity_key' => ['type', 'entity_type', 'entity_id'],
],
];
return $schema;
......@@ -718,3 +733,87 @@ function simple_sitemap_update_8302() {
$settings->save();
}
}
/**
* Add indexes to the simple_sitemap and simple_sitemap_entity_overrides tables.
*/
function simple_sitemap_update_8303() {
$schema = Database::getConnection()->schema();
$spec = [
'fields' => [
'type' => [
'description' => 'Type of sitemap this chunk belongs to.',
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => '',
],
'delta' => [
'description' => 'Delta of the chunk within the type scope.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
],
'status' => [
'description' => 'Flag indicating the publishing status of the chunk.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
],
],
];
$schema->addIndex('simple_sitemap', 'type_status_delta', ['type', 'status', 'delta'], $spec);
$spec = [
'fields' => [
'type' => [
'description' => 'Type of sitemap this override belongs to.',
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
],
'entity_type' => [
'description' => 'Entity type of the overriding entity.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
],
'entity_id' => [
'description' => 'ID of the overriding entity.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
],
],
];
$schema->addIndex('simple_sitemap_entity_overrides', 'entity_key', ['type', 'entity_type', 'entity_id'], $spec);
}
/**
* Add 'entities_per_queue_item' to configuration.
*/
function simple_sitemap_update_8304() {
\Drupal::service('config.factory')
->getEditable('simple_sitemap.settings')
->set('entities_per_queue_item', 50)
->save();
return t("The new 'Entities per queue item' setting has been set to 50 to improve generation performance. This changes the memory footprint during generation, so please make sure to test and adjust performance settings to your needs on the module's settings page.");
}
/**
* Add the link_count field to simple_sitemap table.
*/
function simple_sitemap_update_8305() {
\Drupal::database()->schema()->addField(
'simple_sitemap',
'link_count', [
'description' => 'The number of links in the sitemap.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
]
);
}
......@@ -13,6 +13,8 @@ services:
- '@date.formatter'
- '@datetime.time'
- '@simple_sitemap.queue_worker'
- '@lock'
- '@simple_sitemap.logger'
simple_sitemap.manager:
class: Drupal\simple_sitemap\SimplesitemapManager
......@@ -41,6 +43,7 @@ services:
- '@simple_sitemap.queue'
- '@simple_sitemap.logger'
- '@module_handler'
- '@lock'
simple_sitemap.queue:
class: Drupal\simple_sitemap\Queue\SimplesitemapQueue
......
......@@ -176,6 +176,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#required' => TRUE,
];
$form['simple_sitemap_settings']['advanced']['entities_per_queue_item'] = [
'#type' => 'number',
'#title' => $this->t('Entities per queue item'),
'#min' => 1,
'#description' => $this->t('The number of entities to process in each queue item.<br>Increasing this number will use more memory but will result in less queries improving generation speed.'),
'#default_value' => $this->generator->getSetting('entities_per_queue_item', 50),
];
$this->formHelper->displayRegenerateNow($form['simple_sitemap_settings']);
return parent::buildForm($form, $form_state);
......@@ -204,7 +212,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
'xsl',
'base_url',
'default_variant',
'disable_language_hreflang'] as $setting_name) {
'disable_language_hreflang',
'entities_per_queue_item'] as $setting_name) {
$this->generator->saveSetting($setting_name, $form_state->getValue($setting_name));
}
$this->generator->saveSetting('excluded_languages', array_filter($form_state->getValue('excluded_languages')));
......
......@@ -119,7 +119,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$index_progress = [
'#theme' => 'progress_bar',
'#percent' => $percent,
'#message' => $this->t('@indexed out of @total items have been processed.<br>Each sitemap variant is published after all of its items have been processed.', ['@indexed' => $indexed_count, '@total' => $total_count]),
'#message' => $this->t('@indexed out of @total queue items have been processed.<br>Each sitemap variant is published after all of its items have been processed.', ['@indexed' => $indexed_count, '@total' => $total_count]),
];
$form['simple_sitemap_settings']['status']['progress']['bar']['#markup'] = render($index_progress);
}
......@@ -132,7 +132,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'base_url' => $this->generator->getSetting('base_url', ''),
'default_variant' => $this->generator->getSetting('default_variant', NULL),
];
$sitemap_statuses = $this->fetchSitemapInstanceStatuses();
$sitemap_statuses = $this->fetchSitemapInstanceInfo();
$published_timestamps = $this->fetchSitemapInstancePublishedTimestamps();
foreach ($sitemap_manager->getSitemapTypes() as $type_name => $type_definition) {
if (!empty($variants = $sitemap_manager->getSitemapVariants($type_name, FALSE))) {
......@@ -148,20 +148,22 @@ public function buildForm(array $form, FormStateInterface $form_state) {
];
$form['simple_sitemap_settings']['status']['types'][$type_name]['table'] = [
'#type' => 'table',
'#header' => [$this->t('Variant'), $this->t('Status')],
'#header' => [$this->t('Variant'), $this->t('Status'), $this->t('Link count')],
'#attributes' => ['class' => ['form-item', 'clearfix']],
];
foreach ($variants as $variant_name => $variant_definition) {
if (!isset($sitemap_statuses[$variant_name])) {
$row['name']['data']['#markup'] = '<span title="' . $variant_name . '">' . $this->t($variant_definition['label']) . '</span>';
$row['status'] = $this->t('pending');
$row['count'] = '';
}
else {
switch ($sitemap_statuses[$variant_name]) {
switch ($sitemap_statuses[$variant_name]['status']) {
case 0:
$row['name']['data']['#markup'] = '<span title="' . $variant_name . '">' . $this->t($variant_definition['label']) . '</span>';
$row['status'] = $this->t('generating');
$row['count'] = '';
break;
case 1:
......@@ -169,10 +171,16 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$row['name']['data']['#markup'] = $this->t('<a href="@url" target="_blank">@variant</a>',
['@url' => $sitemap_generator->setSitemapVariant($variant_name)->getSitemapUrl(), '@variant' => $this->t($variant_definition['label'])]
);
$row['status'] = $this->t(($sitemap_statuses[$variant_name] === 1
$row['status'] = $this->t(($sitemap_statuses[$variant_name]['status'] === 1
? 'published on @time'
: 'published on @time, regenerating'
), ['@time' => $this->dateFormatter->format($published_timestamps[$variant_name])]);
// Once the sitemap has been regenerated after
// simple_sitemap_update_8305() there will always be a link
// count.
$row['count'] = $sitemap_statuses[$variant_name]['link_count'] > 0
? $sitemap_statuses[$variant_name]['link_count']
: $this->t('unavailable');
break;
}
}
......@@ -190,7 +198,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
/**
* @return array
* Array of sitemap statuses keyed by variant name.
* Array of sitemap statuses and link counts keyed by variant name.
* Status values:
* 0: Instance is unpublished
* 1: Instance is published
......@@ -198,19 +206,20 @@ public function buildForm(array $form, FormStateInterface $form_state) {
*
* @todo Implement SitemapGeneratorBase::isPublished() per sitemap instead or at least return a constant.
*/
protected function fetchSitemapInstanceStatuses() {
protected function fetchSitemapInstanceInfo() {
$results = $this->db
->query('SELECT type, status FROM {simple_sitemap} GROUP BY type, status')
->query('SELECT type, status, SUM(link_count) as link_count FROM {simple_sitemap} GROUP BY type, status ORDER BY type, status ASC')
->fetchAll();
$instances = [];
$instance_info = [];
foreach ($results as $i => $result) {
$instances[$result->type] = isset($instances[$result->type])
? $result->status + 1
: (int) $result->status;
$instance_info[$result->type] = [
'status' => isset($instance_info[$result->type]) ? $result->status + 1 : (int) $result->status,
'link_count' => (int) $result->link_count,
];
}
return $instances;
return $instance_info;
}
/**
......
......@@ -237,6 +237,7 @@ public function generate(array $links) {
'sitemap_string' => $this->getXml($links),
'sitemap_created' => $this->time->getRequestTime(),
'status' => 0,
'link_count' => count($links),
])->execute();
return $this;
......
......@@ -2,6 +2,8 @@
namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;
use Drupal\Core\Url;
use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
use Drupal\simple_sitemap\EntityHelper;
use Drupal\simple_sitemap\Logger;
use Drupal\simple_sitemap\Simplesitemap;
......@@ -26,6 +28,16 @@ class EntityUrlGenerator extends EntityUrlGeneratorBase {
*/
protected $urlGeneratorManager;
/**
* @var integer
*/
protected $entitiesPerDataset;
/**
* @var \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface
*/
protected $entityMemoryCache;
/**
* EntityUrlGenerator constructor.
* @param array $configuration
......@@ -37,6 +49,7 @@ class EntityUrlGenerator extends EntityUrlGeneratorBase {
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\simple_sitemap\EntityHelper $entityHelper
* @param \Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\UrlGeneratorManager $url_generator_manager
* @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache
*/
public function __construct(
array $configuration,
......@@ -47,7 +60,8 @@ public function __construct(
LanguageManagerInterface $language_manager,
EntityTypeManagerInterface $entity_type_manager,
EntityHelper $entityHelper,
UrlGeneratorManager $url_generator_manager
UrlGeneratorManager $url_generator_manager,
MemoryCacheInterface $memory_cache
) {
parent::__construct(
$configuration,
......@@ -60,6 +74,8 @@ public function __construct(
$entityHelper
);
$this->urlGeneratorManager = $url_generator_manager;
$this->entityMemoryCache = $memory_cache;
$this->entitiesPerDataset = $this->generator->getSetting('entities_per_queue_item', 50);
}
public static function create(
......@@ -76,7 +92,8 @@ public static function create(
$container->get('language_manager'),
$container->get('entity_type.manager'),
$container->get('simple_sitemap.entity_helper'),
$container->get('plugin.manager.simple_sitemap.url_generator')
$container->get('plugin.manager.simple_sitemap.url_generator'),
$container->get('entity.memory_cache')
);
}
......@@ -120,11 +137,20 @@ public function getDataSets() {
// See https://www.drupal.org/project/simple_sitemap/issues/3102450.
$query->accessCheck(FALSE);
$data_set = [
'entity_type' => $entity_type_name,
'id' => [],
];
foreach ($query->execute() as $entity_id) {
$data_sets[] = [
'entity_type' => $entity_type_name,
'id' => $entity_id,
];
$data_set['id'][] = $entity_id;
if (count($data_set['id']) >= $this->entitiesPerDataset) {
$data_sets[] = $data_set;
$data_set['id'] = [];
}
}
// Add the last data set if there are some IDs gathered.
if (!empty($data_set['id'])) {
$data_sets[] = $data_set;
}
}
}
......@@ -138,64 +164,75 @@ public function getDataSets() {
* @inheritdoc
*/
protected function processDataSet($data_set) {
if (empty($entity = $this->entityTypeManager->getStorage($data_set['entity_type'])->load($data_set['id']))) {
$entities = $this->entityTypeManager->getStorage($data_set['entity_type'])->loadMultiple((array) $data_set['id']);
if (empty($entities)) {
return FALSE;
}
$entity_settings = $this->generator
->setVariants($this->sitemapVariant)
->getEntityInstanceSettings($entity->getEntityTypeId(), $entity->id());
$paths = [];
foreach ($entities as $entity) {
$entity_settings = $this->generator
->setVariants($this->sitemapVariant)
->getEntityInstanceSettings($entity->getEntityTypeId(), $entity->id());
if (empty($entity_settings['index'])) {
return FALSE;
}
if (empty($entity_settings['index'])) {
continue;
}
$url_object = $entity->toUrl()->setAbsolute();
$url_object = $entity->toUrl()->setAbsolute();
// Do not include external paths.
if (!$url_object->isRouted()) {
return FALSE;
}
// Do not include external paths.
if (!$url_object->isRouted()) {
continue;
}
return [
'url' => $url_object,
'lastmod' => method_exists($entity, 'getChangedTime')
? date('c', $entity->getChangedTime())
: NULL,
'priority' => isset($entity_settings['priority']) ? $entity_settings['priority'] : NULL,
'changefreq' => !empty($entity_settings['changefreq']) ? $entity_settings['changefreq'] : NULL,
'images' => !empty($entity_settings['include_images'])
? $this->getEntityImageData($entity)
: [],
// Additional info useful in hooks.
'meta' => [
'path' => $url_object->getInternalPath(),
'entity_info' => [
'entity_type' => $entity->getEntityTypeId(),
'id' => $entity->id(),
],
]
];
$paths[] = [
'url' => $url_object,
'lastmod' => method_exists($entity, 'getChangedTime')
? date('c', $entity->getChangedTime())
: NULL,
'priority' => isset($entity_settings['priority']) ? $entity_settings['priority'] : NULL,
'changefreq' => !empty($entity_settings['changefreq']) ? $entity_settings['changefreq'] : NULL,
'images' => !empty($entity_settings['include_images'])
? $this->getEntityImageData($entity)
: [],
// Additional info useful in hooks.
'meta' => [
'path' => $url_object->getInternalPath(),
'entity_info' => [
'entity_type' => $entity->getEntityTypeId(),
'id' => $entity->id(),
],
]
];
}
return $paths;
}
/**
* @inheritdoc
*
* Make sure to clear entity cache so it does not build up resulting in a
* constant increase of memory.
*
* See https://www.drupal.org/project/simple_sitemap/issues/3170261.
*/
public function generate($data_set) {
$result = parent::generate($data_set);
$path_data_sets = $this->processDataSet($data_set);
$url_variant_sets = [];
foreach ($path_data_sets as $key => $path_data) {
if (isset($path_data['url']) && $path_data['url'] instanceof Url) {
$url_object = $path_data['url'];
unset($path_data['url']);
$url_variant_sets[] = $this->getUrlVariants($path_data, $url_object);
}
}
$storage = $this->entityTypeManager->getStorage($data_set['entity_type']);
if (method_exists($storage, 'resetCache')) {
$storage->resetCache([$data_set['id']]);
// Make sure to clear entity memory cache so it does not build up resulting
// in a constant increase of memory.
// See https://www.drupal.org/project/simple_sitemap/issues/3170261 and
// https://www.drupal.org/project/simple_sitemap/issues/3202233
if ($this->entityTypeManager->getDefinition($data_set['entity_type'])->isStaticallyCacheable()) {
$this->entityMemoryCache->deleteAll();
}
return $result;
return array_merge([], ...$url_variant_sets);
}
}
......@@ -13,7 +13,7 @@ trait BatchTrait {
*/
protected $batch;
protected static $batchErrorMessage = 'The generation failed to finish. It can be continued manually on the module\'s setting page, or via drush.';
protected static $batchErrorMessage = 'The generation failed to finish. It can be continued manually on the module\'s settings page, or via drush.';
/**
* @param string $from
......@@ -25,7 +25,7 @@ public function batchGenerateSitemap($from = self::GENERATE_TYPE_FORM, $variants
'title' => $this->t('Generating XML sitemaps'),
'init_message' => $this->t('Initializing...'),
'error_message' => $this->t(self::$batchErrorMessage),
'progress_message' => $this->t('Processing items from the queue.<br>Each sitemap variant is published after all of its items have been processed.'),
'progress_message' => $this->t('Processing items from the queue.<br>Each sitemap variant gets published after all of its items have been processed.'),
'operations' => [[ __CLASS__ . '::' . 'doBatchGenerateSitemap', []]],
'finished' => [__CLASS__, 'finishGeneration'],
];
......@@ -66,7 +66,7 @@ public static function doBatchGenerateSitemap(&$context) {
$processed_element_count = $queue_worker->getProcessedElementCount();
$original_element_count = $queue_worker->getInitialElementCount();
$context['message'] = t('@indexed out of @total total items have been processed.', [
$context['message'] = t('@indexed out of @total total queue items have been processed.', [
'@indexed' => $processed_element_count, '@total' => $original_element_count]);
$context['finished'] = $original_element_count > 0 ? ($processed_element_count / $original_element_count) : 1;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment