Commit b4f4fdd3 authored by drumm's avatar drumm
Browse files

Issue #3117465: Add project NID to project_usage_week_release table

parent ac04fc86
......@@ -82,7 +82,6 @@ function project_usage_retrieve_metadata() {
}
// Load information about projects.
$projdata = array();
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', project_project_node_types())
......@@ -107,7 +106,6 @@ function project_usage_retrieve_metadata() {
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', project_release_release_node_types())
->fieldCondition('field_release_vcs_label', 'value', 'master', '<>')
->execute();
if (isset($result['node'])) {
foreach (array_chunk(array_keys($result['node']), 100) as $releases) {
......@@ -191,6 +189,7 @@ function drush_project_usage_import_usage_stats($week) {
$qcount++;
$query->values([
'nid' => $nid,
'project_nid' => $metadata['projects'][$project_machine_name],
'timestamp' => $week,
'count' => $count,
]);
......
......@@ -42,6 +42,49 @@ function project_usage_update_7000() {
db_drop_table('project_usage_day');
}
/**
* Add {project_usage_week_release}.project_nid field.
*/
function project_usage_update_7002() {
db_add_field('project_usage_week_release', 'project_nid', [
'description' => 'The {node}.nid of the release’s project.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
]);
}
/**
* Fill {project_usage_week_release}.project_nid field.
*/
function project_usage_update_7003() {
$project_release_nids = [];
$result = (new EntityFieldQuery())->entityCondition('entity_type', 'node')
->entityCondition('bundle', project_release_release_node_types())
->execute();
if (isset($result['node'])) {
foreach (array_chunk(array_keys($result['node']), 100) as $releases) {
foreach (node_load_multiple($releases, array(), TRUE) as $release) {
$project_release_nids[$release->field_release_project[LANGUAGE_NONE][0]['target_id']][] = $release->nid;
}
}
}
foreach ($project_release_nids as $project_nid => $release_nids) {
db_update('project_usage_week_release')
->condition('nid', [$release_nids])
->fields(['project_nid' => $project_nid])
->execute();
}
}
/**
* Index {project_usage_week_release}.project_nid field.
*/
function project_usage_update_7004() {
db_add_index('project_usage_week_release', 'timestamp_project_count', ['timestamp', 'project_nid', 'count']);
}
/**
* Remove obsolete configuration.
*/
......@@ -90,10 +133,10 @@ function project_usage_schema() {
);
$schema['project_usage_week_release'] = array(
'description' => 'Table used to store weekly usage information by project and {taxonomy_term_data}.tid.',
'description' => 'Table used to store weekly usage information by release.',
'fields' => array(
'nid' => array(
'description' => 'Primary Key: The {node}.nid of the project.',
'description' => 'Primary Key: The {node}.nid of the release.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
......@@ -106,6 +149,13 @@ function project_usage_schema() {
'not null' => TRUE,
'default' => 0,
),
'project_nid' => [
'description' => 'The {node}.nid of the release’s project.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
'count' => array(
'description' => 'The number of requests.',
'type' => 'int',
......@@ -115,6 +165,9 @@ function project_usage_schema() {
),
),
'primary key' => array('nid', 'timestamp'),
'indexes' => [
'timestamp_project_count' => ['timestamp', 'project_nid', 'count'],
],
);
$schema['cache_project_usage'] = array(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment