unraid / unraid/api

Notifications overview archive count includes duplicates, mismatches actual list

Open
#1,859 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

  • #1817 by @Ajit-Mehrotra — closed without merging
  • #1860 by @Ajit-Mehrotra — closed without merging
bug
Dominant language
TypeScript
Stars
113
Forks
22
Avg merge
10h 40m
Merged PRs (30d)
13

Description

Image

Environment

Unraid OS Version:
7.2.3 (and likely earlier versions)

Are you using a reverse proxy?
No. Tested by accessing server directly.

Pre-submission Checklist

  • I have verified that my Unraid OS is up to date
  • I have tested this issue by accessing my server directly (not through a reverse proxy)
  • This is not an Unraid Connect related issue

Issue Description

The notifications overview returns incorrect archive.total count. The counter shows the same number as unread.total, even when there are 0 archived notifications.

This happens because the legacy notification script writes notifications to both /unread/ and /archive/ directories, and the overview counter does not filter out these duplicates.

Steps to Reproduce

  1. Query the GraphQL API for notifications overview:
    query {
      notifications {
        overview {
          unread { total }
          archive { total }
        }
      }
    }
    
  2. Observe that archive.total equals unread.total (e.g., both show 13)
  3. Query the archive list:
    query {
    notifications {
    list(filter: { type: ARCHIVE, offset: 0, limit: 100 }) {
    id
    }
    }
    }
  4. Observe that the list returns 0 items, contradicting the overview count

Expected Behavior

  • archive.total should reflect the actual number of archived notifications
  • If there are 13 unread and 0 archived, overview should show unread.total: 13 and archive.total: 0

Actual Behavior

  • archive.total shows 13 (same as unread)
  • But fetching the archive list returns 0 notifications
  • The count and actual data are inconsistent

Additional Context

Root Cause (found in source code):

In api/src/unraid-api/graph/resolvers/notifications/notifications.service.ts:

The getNotifications() method correctly filters duplicates from archive (lines 557-563):
const unreads = new Set(await readdir(UNREAD));
files = await this.listFilesInFolder(ARCHIVE, (archives) => {
return archives.filter((file) => !unreads.has(file)); // Filters duplicates
});

However, the overview counters do NOT apply this same filtering:

  • handleNotificationAdd() (lines 111-125) - increments archive counter without checking for duplicates
  • recalculateOverview() (lines 155-193) - counts all files without filtering duplicates

Suggested Fix:

Apply the same duplicate filtering logic to the overview calculation:
// When calculating archive overview, exclude files that exist in unread
const unreads = new Set(await readdir(UNREAD));
const archiveFiles = (await readdir(ARCHIVE)).filter(f => !unreads.has(f));

The comment in the code mentions this is "a temporary measure" for legacy script compatibility, but the fix was only applied to getNotifications() and not to the overview counters.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read api/src/unraid-api/graph/resolvers/notifications/notifications.service.ts, especially getNotifications(), handleNotificationAdd(), and recalculateOverview(). Compare the existing archive duplicate filtering with the overview counter paths. Done means archive.total excludes files also present in unread and matches the archive list for the reported GraphQL query.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.