masugadesign/link-vault-craft-cms

Group Count vs Record totals not same

Closed this issue · 3 comments

Craft 3.5.17.1
LinkVault 3.1.5
PHP 7.3.9
MySQL 5.7.26

I am building this site locally with the trial version of link vault at the moment. I have been testing downloads and have cleared the download history in linkvault via the control panel several times.

I have the following code

{% set topDownloads = craft.linkvault.groupCount('fileName') %}
<table>
  <thead>
    <tr>
      <th>File</th>
      <th>Downloads</th>
    <tr>
  </thead>
  <tbody>
    {% for topDownload in topDownloads %}
      <tr>
        <td>{{ topDownload.fileName }}</td>
        <td>{{ topDownload.census|number_format(0) }}</td>
      <tr>
    {% endfor %}
  </tbody>
</table>

{% set records = craft.linkvault.records.all() %}
{% set allRecordsByAsset = records|group(e => e.fileName) %}
<table>
  <thead>
    <tr>
      <th>File</th>
      <th>Downloads</th>
    <tr>
  </thead>
  <tbody>
    {% for file, recordsByAsset in allRecordsByAsset %}
      <tr>
        <td>{{ file }}</td>
        <td>{{ recordsByAsset|length }}</td>
      <tr>
    {% endfor %}
  </tbody>
</table>

Which is outputting:
Screenshot 2021-01-26 at 11 16 26

It looks like groupCount doesn't get reset if records are deleted from the control panel.
Is that expected?
Is there a parameter that can override that?

That is probably exactly what's happening. The soft deletion is a Craft feature and I used the Yii 2 query builder for groupCount rather than Craft element queries and Yii dosn't factor in soft deletes. I'll probably convert that method to use Craft element queries if possible. Otherwise I will add a parameter to omit soft-deleted records from the results.

Great, thanks, I'll look out for an update. It's looking like it's going to be a really useful add-on for this site.

Link Vault 3.1.6 is now released with fixes to the groupCount template variable parameters as well as the fix for soft deletes in the corresponding service method. I also updated the groupCount example in the readme file.