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

Add getPlagiarismRecordsCount function, and show open case count #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ public function feedAction(
// Add the logged in user's rights to the response, so we can conditionally show links for sysops.
$ret['user_rights'] = $currentUser ? $wikiRepo->getUserRights( $currentUser->username ) : [];

$open_records_count = $copyPatrolRepo->getPlagiarismRecordsCount(
array_merge(
$options,
[
'filter' => CopyPatrolRepository::FILTER_OPEN
]
)
);
// If there are 200 (or more) open records, we just show "200+".
if ( $open_records_count >= 200 ) {
$ret['open_records_count'] = "200+";
} else {
$ret['open_records_count'] = $open_records_count;
}

return $this->render( 'feed.html.twig', $ret );
}

Expand Down
37 changes: 37 additions & 0 deletions src/Repository/CopyPatrolRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Repository;

use DateInterval;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
Expand Down Expand Up @@ -128,6 +129,42 @@ public function getPlagiarismRecords( array $options = [], int $limit = 50 ): ar
->fetchAllAssociative();
}

/**
* Fetch the count of records from the CopyPatrol database, up to $limit.
*
* @param array $options filter and filter user options, should look like:
* string 'filter' Filter to show a certain status: 'all', 'open', or 'reviewed'
* string 'filter_user' Filter SQL to only return records reviewed by given user
* string 'filter_page' Search string (page title)
* boolean 'drafts' returns only records that are in the Draft namespace
* integer 'last_id' offset of where to start fetching records, going by 'diff_id'
* integer 'id' exact submission_id of a record. This will override all other filter options
* string 'lang' The language code of the Wikipedia to query for
* @param int $limit Number of records asked for
* @param string $cacheExpiry Cache expiry time (default 15 minutes)
* @return int Count of CopyPatrol db records.
*/
public function getPlagiarismRecordsCount(
array $options = [],
int $limit = 200,
string $cacheExpiry = 'PT15M'
): int {
// If the count is already cached, return it
if ( $this->cache->hasItem( md5( serialize( $options ) . $limit ) ) ) {
return $this->cache->getItem( md5( serialize( $options ) . $limit ) )->get();
}

// Else, calculate the count and cache it
$count = count( $this->getPlagiarismRecords( $options, $limit ) );
$cacheItem = $this->cache
->getItem( md5( serialize( $options ) . $limit ) )
->set( $count )
// cache for 15 minutes
->expiresAfter( new DateInterval( $cacheExpiry ) );
$this->cache->save( $cacheItem );
return $this->cache->getItem( md5( serialize( $options ) . $limit ) )->get();
}

/**
* Get the top reviewers over the past last 7 days, 30 days, and all-time.
*
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<label>
<input type="radio" name="filter" value="{{ type }}"
{% if filter == type %} checked="checked"{% endif %}
/> {{ msg('form-'~type) }}
/> {{ msg('form-'~type) }} {% if type == "open" %} (<span id="open_records_count" data-count="{{ open_records_count }}">{{ open_records_count }}</span>) {% endif %}
</label>
</span>
{% endfor %}
Expand Down
Loading