Commit 5b12d645 authored by Gaurav Kapoor's avatar Gaurav Kapoor Committed by Gaurav Kapoor
Browse files

Issue #2790405 by gaurav.kapoor: Set proper cache tags and other settings for...

Issue #2790405 by gaurav.kapoor: Set proper cache tags and other settings for the counter block and views
parent fc5f473e
Loading
Loading
Loading
Loading
+1 −2
Changes for config/install/counter.settings.yml: 1 added line, 2 removed lines.
Original line number Diff line number Diff line
@@ -13,8 +13,7 @@ counter_statistic_week: 1
counter_statistic_month: 1
counter_statistic_year: 1
counter_skip_admin: 0
counter_refresh_delay: 10
counter_insert_delay: 1
counter_refresh_on_cron: 1
counter_initial_counter: 0
counter_initial_unique_visitor: 0
counter_initial_since: 0
+2 −5
Changes for config/schema/counter.schema.yml: 2 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -47,12 +47,9 @@ counter.settings:
    counter_skip_admin:
      type: integer
      label: 'Counter skip admin user'
    counter_refresh_delay:
    counter_refresh_on_cron:
      type: integer
      label: 'Counter refresh delay'
    counter_insert_delay:
      type: integer
      label: 'Counter insert delay'
      label: 'Counter refresh on cron run'
    counter_initial_counter:
      type: integer
      label: 'Counter show initial counter'
+9 −1
Changes for counter.install: 9 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -90,8 +90,16 @@ function counter_uninstall() {
/**
 * Implements hook_update_N().
 *
 * Deletes the unwanted counter_data table.
 * Deletes the unwanted counter_data table and configurations.
 */
function counter_update_8101() {
  \Drupal::database()->schema()->dropTable('counter_data');

  $config = \Drupal::configFactory()->getEditable('counter.settings');
  if (!($config->isNew())) {
    $config->set('counter_refresh_on_cron', 1);
    $config->clear('counter_refresh_delay');
    $config->clear('counter_insert_delay');
    $config->save();
  }
}
+9 −0
Changes for counter.module: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
 * The counter module used for displaying Site Counter.
 */

use Drupal\Core\Cache\Cache;
use Drupal\Core\Routing\RouteMatchInterface;

/**
@@ -45,3 +46,11 @@ function counter_theme($existing, $type, $theme, $path) {
    ],
  ];
}

/**
 * Implements hook_cron().
 */
function counter_cron() {
  // Invalidate cache tag for counter block.
  Cache::invalidateTags(['counter_data_refresh']);
}
+6 −14
Changes for src/Form/CounterSettingsAdvanced.php: 6 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -48,18 +48,11 @@ class CounterSettingsAdvanced extends ConfigFormBase {
      '#description' => $this->t("Do not count when visitor has an administrator role."),
    ];

    $form['counter_advanced']['counter_refresh_delay'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Delay before refresh counter data (in second)'),
      '#default_value' => $config->get('counter_refresh_delay'),
      '#description' => $this->t("Delay before re-calculate counter data, otherwise read from previous value."),
    ];

    $form['counter_advanced']['counter_insert_delay'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Delay before next insert (in second)'),
      '#default_value' => $config->get('counter_insert_delay'),
      '#description' => $this->t("Wait for certain second before next insert. Increase this value if your server can not handle too much data recording. Set to 0 for no delay."),
    $form['counter_advanced']['counter_refresh_on_cron'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Refresh counter values on cron run.'),
      '#default_value' => $config->get('counter_refresh_on_cron'),
      '#description' => $this->t("It will make sure cache of the counter block is cleared on cron run. Strongly recommended to keep this enabled for performance reasons."),
    ];

    return parent::buildForm($form, $form_state);
@@ -79,8 +72,7 @@ class CounterSettingsAdvanced extends ConfigFormBase {
    parent::submitForm($form, $form_state);
    $this->config('counter.settings')
      ->set('counter_skip_admin', $form_state->getValue('counter_skip_admin'))
      ->set('counter_refresh_delay', $form_state->getValue('counter_refresh_delay'))
      ->set('counter_insert_delay', $form_state->getValue('counter_insert_delay'))
      ->set('counter_refresh_on_cron', $form_state->getValue('counter_refresh_on_cron'))
      ->save();
  }

Loading