Skip to content

Commit

Permalink
Merge pull request #1833 from bozana/9822
Browse files Browse the repository at this point in the history
pkp/pkp-lib#9822 Increase timeout and improve DB table indexes for usage stats jobs
  • Loading branch information
bozana authored Feb 7, 2025
2 parents 9e791ef + bf15488 commit 36d5be4
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
10 changes: 5 additions & 5 deletions classes/migration/install/MetricsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public function up(): void
$table->string('city', 255)->default('');
$table->string('load_id', 50);

$table->index(['load_id', 'context_id', 'ip'], 'ust_load_id_context_id_ip');
$table->index(['load_id', 'context_id', 'ip', 'user_agent', 'canonical_url'], 'ust_load_id_context_id_ip_ua_url');
});

// Usage stats unique book and chapter item investigations temporary records
Expand Down Expand Up @@ -361,7 +361,7 @@ public function up(): void
$table->string('city', 255)->default('');
$table->string('load_id', 50);

$table->index(['load_id', 'context_id', 'ip'], 'usii_load_id_context_id_ip');
$table->index(['load_id', 'context_id', 'ip', 'user_agent'], 'usii_load_id_context_id_ip_ua');
});

// Usage stats unique book and chapter item requests temporary records
Expand Down Expand Up @@ -402,7 +402,7 @@ public function up(): void
$table->string('city', 255)->default('');
$table->string('load_id', 50);

$table->index(['load_id', 'context_id', 'ip'], 'usir_load_id_context_id_ip');
$table->index(['load_id', 'context_id', 'ip', 'user_agent'], 'usir_load_id_context_id_ip_ua');
});

// Usage stats unique title investigations temporary records
Expand Down Expand Up @@ -442,7 +442,7 @@ public function up(): void
$table->string('city', 255)->default('');
$table->string('load_id', 50);

$table->index(['load_id', 'context_id', 'ip'], 'usti_load_id_context_id_ip');
$table->index(['load_id', 'context_id', 'ip', 'user_agent'], 'usti_load_id_context_id_ip_ua');
});

// Usage stats unique title requests temporary records
Expand Down Expand Up @@ -483,7 +483,7 @@ public function up(): void
$table->string('city', 255)->default('');
$table->string('load_id', 50);

$table->index(['load_id', 'context_id', 'ip'], 'ustr_load_id_context_id_ip');
$table->index(['load_id', 'context_id', 'ip', 'user_agent'], 'ustr_load_id_context_id_ip_ua');
});

// Usage stats institution temporary records
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* @file classes/migration/upgrade/v3_4_0/I9822_ChangeUsageStatsTemporaryTablesIndexes.php
*
* Copyright (c) 2025 Simon Fraser University
* Copyright (c) 2025 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class I9822_ChangeUsageStatsTemporaryTablesIndexes
*
* @brief Consider aditional columns user_agent and canonical_url for the index on temporary usage stats tables to fix/improve the removeDoubleClicks and compileUniqueClicks query.
*/

namespace APP\migration\upgrade\v3_4_0;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use PKP\install\DowngradeNotSupportedException;

class I9822_ChangeUsageStatsTemporaryTablesIndexes extends \PKP\migration\upgrade\v3_4_0\I9822_ChangeUsageStatsTemporaryTablesIndexes
{
/**
* Run the migration.
*/
public function up(): void
{
Schema::table('usage_stats_unique_title_investigations_temporary_records', function (Blueprint $table) {
if (Schema::hasIndex('usage_stats_unique_title_investigations_temporary_records', 'usti_load_id_context_id_ip')) {
$table->dropIndex('usti_load_id_context_id_ip');
}
if (!Schema::hasIndex('usage_stats_unique_title_investigations_temporary_records', 'usti_load_id_context_id_ip_ua')) {
$table->index(['load_id', 'context_id', 'ip', 'user_agent'], 'usti_load_id_context_id_ip_ua');
}
});
Schema::table('usage_stats_unique_title_requests_temporary_records', function (Blueprint $table) {
if (Schema::hasIndex('usage_stats_unique_title_requests_temporary_records', 'ustr_load_id_context_id_ip')) {
$table->dropIndex('ustr_load_id_context_id_ip');
}
if (!Schema::hasIndex('usage_stats_unique_title_requests_temporary_records', 'ustr_load_id_context_id_ip_ua')) {
$table->index(['load_id', 'context_id', 'ip', 'user_agent'], 'ustr_load_id_context_id_ip_ua');
}
});
parent::up();
}

/**
* Reverse the downgrades
*
* @throws DowngradeNotSupportedException
*/
public function down(): void
{
throw new DowngradeNotSupportedException();
}
}
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<upgrade minversion="3.4.0.0" maxversion="3.4.0.5">
<!-- Only new 3.4 installations need this fix -->
<migration class="PKP\migration\upgrade\v3_4_0\I8592_SiteNotificationSubscriptions"/>
<migration class="APP\migration\upgrade\v3_4_0\I9822_ChangeUsageStatsTemporaryTablesIndexes"/>
</upgrade>

<upgrade minversion="3.1.0.0" maxversion="3.4.9.9">
Expand Down
2 changes: 2 additions & 0 deletions jobs/statistics/CompileUniqueInvestigations.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

class CompileUniqueInvestigations extends BaseJob
{
public int $timeout = 600;

/**
* Create a new job instance.
*
Expand Down
2 changes: 2 additions & 0 deletions jobs/statistics/CompileUniqueRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

class CompileUniqueRequests extends BaseJob
{
public int $timeout = 600;

/**
* Create a new job instance.
*
Expand Down

0 comments on commit 36d5be4

Please sign in to comment.