diff --git a/conf/cmi/core.extension.yml b/conf/cmi/core.extension.yml index 53b23aa3..ffd00fc3 100644 --- a/conf/cmi/core.extension.yml +++ b/conf/cmi/core.extension.yml @@ -10,6 +10,7 @@ module: asu_apartment_search: 0 asu_api: 0 asu_application: 0 + asu_clear_cache: 0 asu_content: 0 asu_content_alter: 0 asu_csv_import: 0 diff --git a/conf/cmi/ultimate_cron.job.asu_api_cron.yml b/conf/cmi/ultimate_cron.job.asu_api_cron.yml index b92b612d..c22ba50c 100644 --- a/conf/cmi/ultimate_cron.job.asu_api_cron.yml +++ b/conf/cmi/ultimate_cron.job.asu_api_cron.yml @@ -6,7 +6,7 @@ dependencies: - asu_api title: 'Default cron handler' id: asu_api_cron -weight: 0 +weight: -12 module: asu_api callback: asu_api_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.asu_application_cron.yml b/conf/cmi/ultimate_cron.job.asu_application_cron.yml index aeaf1d83..728c6ead 100644 --- a/conf/cmi/ultimate_cron.job.asu_application_cron.yml +++ b/conf/cmi/ultimate_cron.job.asu_application_cron.yml @@ -6,7 +6,7 @@ dependencies: - asu_application title: 'Default cron handler' id: asu_application_cron -weight: 0 +weight: -11 module: asu_application callback: asu_application_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.asu_clear_cache_cron.yml b/conf/cmi/ultimate_cron.job.asu_clear_cache_cron.yml new file mode 100644 index 00000000..dd8eec6a --- /dev/null +++ b/conf/cmi/ultimate_cron.job.asu_clear_cache_cron.yml @@ -0,0 +1,29 @@ +uuid: 310bcedf-04c9-4684-b38f-6244b1348e47 +langcode: fi +status: true +dependencies: + module: + - asu_clear_cache +title: 'Default cron handler' +id: asu_clear_cache_cron +weight: 1 +module: asu_clear_cache +callback: asu_clear_cache_cron +scheduler: + id: simple + configuration: + rules: + - '*/5+@ * * * *' +launcher: + id: serial + configuration: + timeouts: + lock_timeout: 3600 + launcher: + thread: 0 +logger: + id: database + configuration: + method: '3' + expire: 1209600 + retain: 1000 diff --git a/conf/cmi/ultimate_cron.job.asu_content_cron.yml b/conf/cmi/ultimate_cron.job.asu_content_cron.yml index 2f86fca2..22d60516 100644 --- a/conf/cmi/ultimate_cron.job.asu_content_cron.yml +++ b/conf/cmi/ultimate_cron.job.asu_content_cron.yml @@ -6,7 +6,7 @@ dependencies: - asu_content title: 'Default cron handler' id: asu_content_cron -weight: 0 +weight: -10 module: asu_content callback: asu_content_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.content_lock_timeout_cron.yml b/conf/cmi/ultimate_cron.job.content_lock_timeout_cron.yml index e44ca13d..cd8862f2 100644 --- a/conf/cmi/ultimate_cron.job.content_lock_timeout_cron.yml +++ b/conf/cmi/ultimate_cron.job.content_lock_timeout_cron.yml @@ -6,7 +6,7 @@ dependencies: - content_lock_timeout title: 'Default cron handler' id: content_lock_timeout_cron -weight: 0 +weight: -9 module: content_lock_timeout callback: content_lock_timeout_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.elasticsearch_connector_cron.yml b/conf/cmi/ultimate_cron.job.elasticsearch_connector_cron.yml index f24d4272..97f0e01a 100644 --- a/conf/cmi/ultimate_cron.job.elasticsearch_connector_cron.yml +++ b/conf/cmi/ultimate_cron.job.elasticsearch_connector_cron.yml @@ -6,7 +6,7 @@ dependencies: - elasticsearch_connector title: 'Default cron handler' id: elasticsearch_connector_cron -weight: 0 +weight: -8 module: elasticsearch_connector callback: elasticsearch_connector_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.field_cron.yml b/conf/cmi/ultimate_cron.job.field_cron.yml index 78e733fa..0671e1f8 100644 --- a/conf/cmi/ultimate_cron.job.field_cron.yml +++ b/conf/cmi/ultimate_cron.job.field_cron.yml @@ -6,7 +6,7 @@ dependencies: - field title: 'Purges deleted Field API data' id: field_cron -weight: 0 +weight: 4 module: field callback: field_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.file_cron.yml b/conf/cmi/ultimate_cron.job.file_cron.yml index 2339301a..28f03839 100644 --- a/conf/cmi/ultimate_cron.job.file_cron.yml +++ b/conf/cmi/ultimate_cron.job.file_cron.yml @@ -6,7 +6,7 @@ dependencies: - file title: 'Deletes temporary files' id: file_cron -weight: 0 +weight: 3 module: file callback: file_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.flysystem_cron.yml b/conf/cmi/ultimate_cron.job.flysystem_cron.yml index 486c15b6..dbf9a3f3 100644 --- a/conf/cmi/ultimate_cron.job.flysystem_cron.yml +++ b/conf/cmi/ultimate_cron.job.flysystem_cron.yml @@ -6,7 +6,7 @@ dependencies: - flysystem title: 'Default cron handler' id: flysystem_cron -weight: 0 +weight: -7 module: flysystem callback: flysystem_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.honeypot_cron.yml b/conf/cmi/ultimate_cron.job.honeypot_cron.yml index 5e91b047..f517aab6 100644 --- a/conf/cmi/ultimate_cron.job.honeypot_cron.yml +++ b/conf/cmi/ultimate_cron.job.honeypot_cron.yml @@ -6,7 +6,7 @@ dependencies: - honeypot title: 'Default cron handler' id: honeypot_cron -weight: 0 +weight: -6 module: honeypot callback: honeypot_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.imagecache_external_cron.yml b/conf/cmi/ultimate_cron.job.imagecache_external_cron.yml index 005d33aa..68229e88 100644 --- a/conf/cmi/ultimate_cron.job.imagecache_external_cron.yml +++ b/conf/cmi/ultimate_cron.job.imagecache_external_cron.yml @@ -6,7 +6,7 @@ dependencies: - imagecache_external title: 'Default cron handler' id: imagecache_external_cron -weight: 0 +weight: -5 module: imagecache_external callback: imagecache_external_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.locale_cron.yml b/conf/cmi/ultimate_cron.job.locale_cron.yml index 5c250040..4b1e79cf 100644 --- a/conf/cmi/ultimate_cron.job.locale_cron.yml +++ b/conf/cmi/ultimate_cron.job.locale_cron.yml @@ -6,7 +6,7 @@ dependencies: - locale title: 'Default cron handler' id: locale_cron -weight: 0 +weight: -4 module: locale callback: locale_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.node_cron.yml b/conf/cmi/ultimate_cron.job.node_cron.yml index 71c50c2b..8b4681d3 100644 --- a/conf/cmi/ultimate_cron.job.node_cron.yml +++ b/conf/cmi/ultimate_cron.job.node_cron.yml @@ -6,7 +6,7 @@ dependencies: - node title: 'Updates search rankings for nodes' id: node_cron -weight: 0 +weight: 7 module: node callback: node_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.redirect_404_cron.yml b/conf/cmi/ultimate_cron.job.redirect_404_cron.yml index 5c3a98c4..b83f04e2 100644 --- a/conf/cmi/ultimate_cron.job.redirect_404_cron.yml +++ b/conf/cmi/ultimate_cron.job.redirect_404_cron.yml @@ -6,7 +6,7 @@ dependencies: - redirect_404 title: 'Default cron handler' id: redirect_404_cron -weight: 0 +weight: -3 module: redirect_404 callback: redirect_404_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.scheduler_cron.yml b/conf/cmi/ultimate_cron.job.scheduler_cron.yml index 4f3e7355..d4b36b8e 100644 --- a/conf/cmi/ultimate_cron.job.scheduler_cron.yml +++ b/conf/cmi/ultimate_cron.job.scheduler_cron.yml @@ -6,7 +6,7 @@ dependencies: - scheduler title: 'Default cron handler' id: scheduler_cron -weight: 0 +weight: -2 module: scheduler callback: scheduler_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.simple_sitemap_cron.yml b/conf/cmi/ultimate_cron.job.simple_sitemap_cron.yml index 37b87e93..b42c32f3 100644 --- a/conf/cmi/ultimate_cron.job.simple_sitemap_cron.yml +++ b/conf/cmi/ultimate_cron.job.simple_sitemap_cron.yml @@ -6,7 +6,7 @@ dependencies: - simple_sitemap title: 'Default cron handler' id: simple_sitemap_cron -weight: 0 +weight: 2 module: simple_sitemap callback: simple_sitemap_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.system_cron.yml b/conf/cmi/ultimate_cron.job.system_cron.yml index 0e9c043f..90928d39 100644 --- a/conf/cmi/ultimate_cron.job.system_cron.yml +++ b/conf/cmi/ultimate_cron.job.system_cron.yml @@ -6,7 +6,7 @@ dependencies: - system title: 'Cleanup (caches, batch, flood, temp-files, etc.)' id: system_cron -weight: 0 +weight: -13 module: system callback: system_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.ultimate_cron_cron.yml b/conf/cmi/ultimate_cron.job.ultimate_cron_cron.yml index 18cb6275..d5cf4e10 100644 --- a/conf/cmi/ultimate_cron.job.ultimate_cron_cron.yml +++ b/conf/cmi/ultimate_cron.job.ultimate_cron_cron.yml @@ -4,7 +4,7 @@ status: true dependencies: { } title: 'Runs internal cleanup operations' id: ultimate_cron_cron -weight: 0 +weight: 5 module: ultimate_cron callback: ultimate_cron_cron scheduler: diff --git a/conf/cmi/ultimate_cron.job.ultimate_cron_queue_asu_content_queue_worker.yml b/conf/cmi/ultimate_cron.job.ultimate_cron_queue_asu_content_queue_worker.yml new file mode 100644 index 00000000..533be1cf --- /dev/null +++ b/conf/cmi/ultimate_cron.job.ultimate_cron_queue_asu_content_queue_worker.yml @@ -0,0 +1,20 @@ +uuid: ed515030-6598-4b75-b0fd-657a69367024 +langcode: en +status: true +dependencies: + module: + - asu_content +title: 'Queue: Asu content apartment update worker' +id: ultimate_cron_queue_asu_content_queue_worker +weight: -1 +module: asu_content +callback: 'ultimate_cron.queue_worker:queueCallback' +scheduler: + id: simple + configuration: + rules: + - '* * * * *' +launcher: + id: serial +logger: + id: database diff --git a/conf/cmi/ultimate_cron.job.ultimate_cron_queue_entity_reference_revisions_orphan_purger.yml b/conf/cmi/ultimate_cron.job.ultimate_cron_queue_entity_reference_revisions_orphan_purger.yml new file mode 100644 index 00000000..8a04e521 --- /dev/null +++ b/conf/cmi/ultimate_cron.job.ultimate_cron_queue_entity_reference_revisions_orphan_purger.yml @@ -0,0 +1,20 @@ +uuid: 51744f57-3447-48d6-8386-2280c3eea12a +langcode: en +status: true +dependencies: + module: + - entity_reference_revisions +title: 'Queue: Entity Reference Revisions Orphan Purger' +id: ultimate_cron_queue_entity_reference_revisions_orphan_purger +weight: 8 +module: entity_reference_revisions +callback: 'ultimate_cron.queue_worker:queueCallback' +scheduler: + id: simple + configuration: + rules: + - '* * * * *' +launcher: + id: serial +logger: + id: database diff --git a/conf/cmi/ultimate_cron.job.ultimate_cron_queue_entity_usage_regenerate_queue.yml b/conf/cmi/ultimate_cron.job.ultimate_cron_queue_entity_usage_regenerate_queue.yml new file mode 100644 index 00000000..a3e203e3 --- /dev/null +++ b/conf/cmi/ultimate_cron.job.ultimate_cron_queue_entity_usage_regenerate_queue.yml @@ -0,0 +1,20 @@ +uuid: 4c346814-7761-4eb9-ba08-fd4eb7ac723c +langcode: en +status: true +dependencies: + module: + - entity_usage +title: 'Queue: Entity Usage Regenerate Tracking Queue' +id: ultimate_cron_queue_entity_usage_regenerate_queue +weight: 9 +module: entity_usage +callback: 'ultimate_cron.queue_worker:queueCallback' +scheduler: + id: simple + configuration: + rules: + - '* * * * *' +launcher: + id: serial +logger: + id: database diff --git a/conf/cmi/ultimate_cron.job.ultimate_cron_queue_imagecache_external_flush_images.yml b/conf/cmi/ultimate_cron.job.ultimate_cron_queue_imagecache_external_flush_images.yml new file mode 100644 index 00000000..482c145a --- /dev/null +++ b/conf/cmi/ultimate_cron.job.ultimate_cron_queue_imagecache_external_flush_images.yml @@ -0,0 +1,20 @@ +uuid: 1fafd13b-580e-4bfb-833f-4f106f84f313 +langcode: en +status: true +dependencies: + module: + - imagecache_external +title: 'Queue: Imagechache external flush images.' +id: ultimate_cron_queue_imagecache_external_flush_images +weight: 10 +module: imagecache_external +callback: 'ultimate_cron.queue_worker:queueCallback' +scheduler: + id: simple + configuration: + rules: + - '* * * * *' +launcher: + id: serial +logger: + id: database diff --git a/conf/cmi/ultimate_cron.job.ultimate_cron_queue_locale_translation.yml b/conf/cmi/ultimate_cron.job.ultimate_cron_queue_locale_translation.yml new file mode 100644 index 00000000..58eb0fc5 --- /dev/null +++ b/conf/cmi/ultimate_cron.job.ultimate_cron_queue_locale_translation.yml @@ -0,0 +1,20 @@ +uuid: e7504516-b20b-41e8-8fcf-2b29fa22e56e +langcode: en +status: true +dependencies: + module: + - locale +title: 'Queue: Update translations' +id: ultimate_cron_queue_locale_translation +weight: 12 +module: locale +callback: 'ultimate_cron.queue_worker:queueCallback' +scheduler: + id: simple + configuration: + rules: + - '* * * * *' +launcher: + id: serial +logger: + id: database diff --git a/conf/cmi/ultimate_cron.job.ultimate_cron_queue_media_entity_thumbnail.yml b/conf/cmi/ultimate_cron.job.ultimate_cron_queue_media_entity_thumbnail.yml new file mode 100644 index 00000000..3f9f260c --- /dev/null +++ b/conf/cmi/ultimate_cron.job.ultimate_cron_queue_media_entity_thumbnail.yml @@ -0,0 +1,20 @@ +uuid: 0a8680f1-97c8-4cc4-b7fb-6f50f4199d76 +langcode: en +status: true +dependencies: + module: + - media +title: 'Queue: Thumbnail downloader' +id: ultimate_cron_queue_media_entity_thumbnail +weight: 11 +module: media +callback: 'ultimate_cron.queue_worker:queueCallback' +scheduler: + id: simple + configuration: + rules: + - '* * * * *' +launcher: + id: serial +logger: + id: database diff --git a/conf/cmi/ultimate_cron.job.update_cron.yml b/conf/cmi/ultimate_cron.job.update_cron.yml index 4f05c563..a52d52e3 100644 --- a/conf/cmi/ultimate_cron.job.update_cron.yml +++ b/conf/cmi/ultimate_cron.job.update_cron.yml @@ -6,7 +6,7 @@ dependencies: - update title: 'Update indexes' id: update_cron -weight: 0 +weight: 6 module: update callback: update_cron scheduler: diff --git a/conf/cmi/ultimate_cron.settings.yml b/conf/cmi/ultimate_cron.settings.yml index f6316b32..d0cb52b4 100644 --- a/conf/cmi/ultimate_cron.settings.yml +++ b/conf/cmi/ultimate_cron.settings.yml @@ -2,7 +2,7 @@ _core: default_config_hash: xNvhVNcCJsZiYwYTw9TTnRv1SjLVO7H5BCK1U8Brvfo bypass_transactional_safe_connection: false queue: - enabled: false + enabled: true timeouts: lease_time: !!float 30 time: !!float 15 diff --git a/public/modules/custom/asu_clear_cache/asu_clear_cache.info.yml b/public/modules/custom/asu_clear_cache/asu_clear_cache.info.yml new file mode 100644 index 00000000..531a28e9 --- /dev/null +++ b/public/modules/custom/asu_clear_cache/asu_clear_cache.info.yml @@ -0,0 +1,6 @@ +name: 'ASU - Clear cache' +type: module +description: 'ASU - Clear cache cron.' +core: 8.x +core_version_requirement: ^8 || ^9 || ^10 +package: 'ASU' diff --git a/public/modules/custom/asu_clear_cache/asu_clear_cache.module b/public/modules/custom/asu_clear_cache/asu_clear_cache.module new file mode 100644 index 00000000..b3ad95d9 --- /dev/null +++ b/public/modules/custom/asu_clear_cache/asu_clear_cache.module @@ -0,0 +1,32 @@ +select('node_field_data', 'n'); + $query->condition('n.type', 'project'); + $query->condition('n.status', 1); + $query->condition('n.changed', $time_ago, '>='); + $query->fields('n', ['nid']); + + $projects = $query->execute()->fetchAll(); + + if (count($projects) > 0) { + foreach ($projects as $project) { + $project = Node::load($project->nid); + // Clear listing page cache. + $cid = 'asu_rest:apartment_list:' . $project->getOwnershipType(); + \Drupal::cache()->delete($cid); + } + } +} diff --git a/public/modules/custom/asu_content/asu_content.module b/public/modules/custom/asu_content/asu_content.module index 2f39d9e3..cc72c757 100644 --- a/public/modules/custom/asu_content/asu_content.module +++ b/public/modules/custom/asu_content/asu_content.module @@ -236,7 +236,7 @@ function asu_content_entity_update($entity) { $entity->getType() == 'project' && $entity->hasField('field_apartments') ) { - clearListCache($entity); + asuQueueWorker($entity); } } @@ -271,7 +271,7 @@ function asu_content_node_insert(Node $node) { $node->get('field_apartments')->setValue([$apartment]); $node->save(); - clearListCache($node); + asuQueueWorker($node); } } @@ -279,7 +279,7 @@ function asu_content_node_insert(Node $node) { method_exists($node, 'getType') && $node->getType() == 'apartment' ) { - clearListCache($node); + asuQueueWorker($node); } } @@ -339,14 +339,14 @@ function asu_content_cron() { /** * */ -function clearListCache($entity) { +function asuQueueWorker($entity) { if ( $entity instanceof Apartment && method_exists($entity, 'getType') && $entity->getType() == 'apartment' ) { if ($project = $entity->getProject()) { - clearCache($project); + asuSetQueueWorker($project); } } @@ -355,40 +355,24 @@ function clearListCache($entity) { method_exists($entity, 'getType') && $entity->getType() == 'project' ) { - clearCache($entity); + asuSetQueueWorker($entity); } } /** * */ -function clearCache($project) { +function asuSetQueueWorker($project) { if ($project->getOwnershipType()) { - // Load search api indexes. - $indexes = Index::loadMultiple(); // Get project apartment entities. $apartment_entities = $project->getApartmentEntities(); - $apartments_ids = []; + $queue = \Drupal::service('queue')->get('asu_content_queue_worker'); // Get apartment ids. foreach ($apartment_entities as $apartments_id) { - $apartments_ids[] = $apartments_id->id(); + $item = new \stdClass(); + $item->nid = $apartments_id->id(); + $queue->createItem($item); } - - // Convert apartment id's search api indexing format. - $apartments_index = function ($entity_id) { - return $entity_id . ':fi'; - }; - $apartments_index = array_map($apartments_index, $apartments_ids); - - // Trigger search api index update. - foreach ($indexes as $index) { - $index->trackItemsUpdated('entity:node', $apartments_index); - $index->indexItems(); - } - - // Clear listing page cache. - $cid = 'asu_rest:apartment_list:' . $project->getOwnershipType(); - \Drupal::cache()->delete($cid); } } diff --git a/public/modules/custom/asu_content/asu_content.services.yml b/public/modules/custom/asu_content/asu_content.services.yml index 03ba40e5..0b83042f 100644 --- a/public/modules/custom/asu_content/asu_content.services.yml +++ b/public/modules/custom/asu_content/asu_content.services.yml @@ -5,3 +5,8 @@ services: asu_content.collect_reverse_entity: class: Drupal\asu_content\CollectReverseEntity arguments: ['@entity_type.manager','@entity_field.manager','@plugin.manager.field.field_type', '@logger.channel.asu'] + asu_content.queue_worker: + class: Drupal\asu_content\Plugin\QueueWorker\ApartmentUpdateWorker + arguments: ['@entity_type.manager'] + tags: + - { name: queue_worker } diff --git a/public/modules/custom/asu_content/src/Plugin/QueueWorker/ApartmentUpdateWorker.php b/public/modules/custom/asu_content/src/Plugin/QueueWorker/ApartmentUpdateWorker.php new file mode 100644 index 00000000..d1fe0f14 --- /dev/null +++ b/public/modules/custom/asu_content/src/Plugin/QueueWorker/ApartmentUpdateWorker.php @@ -0,0 +1,65 @@ +entityTypeManager = $entity_type_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity_type.manager') + ); + } + + /** + * {@inheritdoc} + */ + public function processItem($data) { + $entity = $this->entityTypeManager->getStorage('node')->load($data->nid); + $entity->save(); + } + +}