Commit ecc8b17e authored by drumm's avatar drumm
Browse files

Issue #3117465: Stop updating the project_usage_week_project table

parent 72423d61
......@@ -73,17 +73,8 @@ function project_usage_retrieve_metadata() {
static $data = array();
if (empty($data)) {
// Load core api versions.
foreach (taxonomy_get_tree(variable_get('project_release_api_vocabulary', '')) as $term) {
// Quick ugly hack to skip drupal < 5.x.
if (strlen($term->name) == 3) {
$coreterms[$term->name] = $term->tid;
}
}
// Load information about projects.
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
$result = (new EntityFieldQuery())->entityCondition('entity_type', 'node')
->entityCondition('bundle', project_project_node_types())
->fieldCondition('field_project_type', 'value', 'full', '=')
->execute();
......@@ -104,23 +95,19 @@ function project_usage_retrieve_metadata() {
}
// Load information about releases.
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
$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']), 200) as $releases) {
foreach (node_load_multiple($releases, array(), TRUE) as $release) {
$project_name = $projnames[$release->field_release_project[LANGUAGE_NONE][0]['target_id']];
$releasedata[$project_name]['projectname'] = $project_name;
$releasedata[$project_name]['project_nid'] = $release->field_release_project[LANGUAGE_NONE][0]['target_id'];
$releasedata[$project_name][$release->field_release_version[LANGUAGE_NONE][0]['value']]['release_nid'] = $release->nid;
}
drupal_static_reset();
}
}
$data['terms'] = $coreterms;
$data['projects'] = $projnids;
$data['releases'] = $releasedata;
}
......@@ -144,14 +131,13 @@ function drush_project_usage_import_usage_stats($week) {
drush_log(dt('Reading usage counts.'));
$project_releasecounts_fh = _project_usage_open_file($count_file_path . "/" . $week . '.releasecounts');
$project_api_counts = [];
$release_counts = [];
while ($line = fgets($project_releasecounts_fh)) {
$nid = 0;
$term = 0;
// Split up $line into its components.
list($count, $pdata) = explode(' ', trim($line), 2);
list($project_machine_name, $rel_ver, $maj_api) = explode('|', $pdata, 3);
list($project_machine_name, $rel_ver) = explode('|', $pdata, 3);
// Skip projects that are not ours.
if (empty($metadata['releases'][$project_machine_name][$rel_ver]['release_nid'])) {
......@@ -159,12 +145,6 @@ function drush_project_usage_import_usage_stats($week) {
}
// Add up counts.
if (isset($project_api_counts[$project_machine_name][$maj_api])) {
$project_api_counts[$project_machine_name][$maj_api] += $count;
}
else {
$project_api_counts[$project_machine_name][$maj_api] = $count;
}
$nid = $metadata['releases'][$project_machine_name][$rel_ver]['release_nid'];
if (isset($release_counts[$project_machine_name][$nid])) {
$release_counts[$project_machine_name][$nid] += $count;
......@@ -207,51 +187,6 @@ function drush_project_usage_import_usage_stats($week) {
$query->execute();
}
drush_log(dt("Importing Project stats."));
// Clear out existing data.
db_delete('project_usage_week_project')
->condition('timestamp', $week)
->execute();
// Load in new counts.
$qcount = 0;
$query = db_insert('project_usage_week_project')
->fields(array('nid', 'timestamp', 'tid', 'count'));
// Update the project major API counts based on the aggregated counts from
// the releases.
drush_log(dt('Begin updating @week tallies on database', ['@week' => $week]));
foreach ($project_api_counts as $project_machine_name => $maj_apis) {
foreach ($maj_apis as $maj_api => $count) {
$nid = $metadata['projects'][$project_machine_name];
$term = isset($metadata['terms'][$maj_api]) ? $metadata['terms'][$maj_api] : 0;
if (!empty($nid) && !empty($term)) {
$qcount++;
$query->values(array(
'nid' => $nid,
'timestamp' => $week,
'tid' => $term,
'count' => $count,
));
}
if ($qcount > 1000) {
$query->execute();
$qcount = 0;
$query = db_insert('project_usage_week_project')->fields([
'nid',
'timestamp',
'tid',
'count',
]);
}
}
}
if ($qcount) {
$query->execute();
}
drush_log(dt("End updating @week tallies on database.", array('@week' => $week)));
project_usage_get_active_weeks(TRUE);
}
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