Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout and memory exhaust issues when trying to access the /contribution-count page. #12

Closed
gkapoor121212 opened this issue Dec 20, 2021 · 3 comments

Comments

@gkapoor121212
Copy link
Contributor

gkapoor121212 commented Dec 20, 2021

Due to the way, contribution count is being calculated the page /contribution-count isn't loading. The following pre-process consumes a lot of memory.

 * Implements hook_preprocess_views_view().
 *
 * CONT-7 Calculate patches and contributions based on filtered result .
 */
function contrib_tracker_preprocess_views_view(&$variables) {
  $view = $variables['view'];
  $rows = $variables['rows'][0]['#rows'] ?? [];
  if ($view->storage->id() == 'contribution_count' &&
    $view->current_display == 'contribution_report') {

    // Total contributions.
    $variables['totalContribution'] = $view->total_rows;

    // Number of total patches.
    $variables['totalPatches'] = array_sum(array_map(fn($rows) => $rows['#row']->_entity->get('field_code_contrib_patches_count')->value, $rows));

    // Number of contributions with at least a single patch.
    $variables['contributionWithPatches'] = count(array_filter($rows, fn($rows) => $rows['#row']->_entity->get('field_code_contrib_patches_count')->value >= 1));
  }
}

in the contrib_tracker.module.

Instead of using a view page to show statistics, we should add a controller/block which calculates statistics using entity queries.

@hussainweb
Copy link
Member

hussainweb commented Dec 20, 2021

Agreed. This is related (duplicate) to #6.

gkapoor121212 added a commit to gkapoor121212/backend that referenced this issue Dec 21, 2021
@gkapoor121212
Copy link
Contributor Author

@hussainweb I have added a draft MR, where I have introduced a new service which will have all the methods for counting contribution statistics, a controller which will be called when users will access '/contribution-count' page. We can add more functions to this service later on when working on Gamification Issue (#8). Do check the implementation and let me know your thoughts.

Also, how important is the stats 'Total Patches' ? The way number of patches are stored currently, we will have to iterate through all the code contribution nodes and then get that sum which is very memory/time consuming operation. We can add appropriate caching but that cache will have to refreshed whenever a new code contribution node is added. Do you have any other solution to calculate this? Can we store this number somewhere else in the system and increment it if new patch is submitted?

gkapoor121212 added a commit to gkapoor121212/backend that referenced this issue Dec 29, 2021
gkapoor121212 added a commit to gkapoor121212/backend that referenced this issue Dec 30, 2021
gkapoor121212 added a commit to gkapoor121212/backend that referenced this issue Dec 30, 2021
hussainweb added a commit that referenced this issue Jun 29, 2022
Issue #12 by gkapoor121212: Add controller for contribution …
@hussainweb
Copy link
Member

This is fixed in #14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants