forgejo/models
Gergely Nagy 9cb2aa989a
Teach activities.GetFeeds() how to avoid returning duplicates
Before explaining the fix itself, lets look at the `action` table, and
how it is populated. Data is only ever inserted into it via
`activities_model.NotifyWatchers`, which will:

- Insert a row for each activity with `UserID` set to the acting user's
  ID - this is the original activity, and is always inserted if anything
  is to be inserted at all.
- It will insert a copy of each activity with the `UserID` set to the
  repo's owner, if the owner is an Organization, and isn't the acting
  user.
- It will insert a copy of each activity for every watcher of the repo,
  as long as the watcher in question has read permission to the repo
  unit the activity is about.

This means that if a repository belongs to an organizations, for most
activities, it will have at least two rows in the table. For
repositories watched by people other than their owner, an additional row
for each watcher.

These are useful duplicates, because they record which activities are
relevant for a particular user. However, for cases where we wish to see
the activities that happen around a repository, without limiting the
results to a particular user, we're *not* interested in the duplicates
stored for the watchers and the org. We only need the originals.

And this is what this change does: it introduces an additional option to
`GetFeedsOptions`: `OnlyPerformedByActor`. When this option is set,
`activities.GetFeeds()` will only return the original activities, where
the user id and the acting user id are the same. As these are *always*
inserted, we're not missing out on any activities. We're just getting
rid of the duplicates. As this is an additional `AND` condition, it can
never introduce items that would not have been included in the result
set before, it can only reduce, not extend.

These duplicates were only affecting call sites where `RequestedRepo`
was set, but `RequestedUser` and `RequestedTeam` were not. Both of those
call sites were updated to set `OnlyPerformedByActor`. As a result,
repository RSS feeds, and the `/repos/{owner}/{repo}/activities/feeds`
API end points no longer return dupes, only the original activities.

Rather than hardcoding this behaviour into `GetFeeds()` itself, I chose
to implement it as an explicit option, for the sake of clarity.

Fixes Codeberg/Community#684, and addresses gitea#20986.

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
2024-05-09 18:33:33 +02:00
..
actions Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00
activities Teach activities.GetFeeds() how to avoid returning duplicates 2024-05-09 18:33:33 +02:00
admin Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
asymkey Enable more revive linter rules (#30608) 2024-04-28 15:39:00 +02:00
auth Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00
avatars Replace 10 more gt- classes with tw- (#29945) 2024-03-26 19:04:27 +01:00
db Enable more revive linter rules (#30608) 2024-04-28 15:39:00 +02:00
dbfs make writing main test easier (#27270) 2023-09-28 01:38:53 +00:00
fixtures Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00
forgejo/semver [SEMVER] store SemVer in ForgejoSemVer after a database upgrade 2024-02-05 14:44:33 +01:00
forgejo_migrations Drop Gitea-specific columns from two tables 2024-04-26 10:34:06 +02:00
git Fix duplicate status check contexts (#30660) 2024-05-05 08:48:45 +01:00
issues Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00
migrations Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00
organization Resolve lint for unused parameter and unnecessary type arguments (#30750) 2024-05-05 08:38:16 +01:00
packages Fix package list performance (#30520) 2024-04-21 16:28:16 +02:00
perm Users with read permission of pull requests can be assigned too (#27263) 2024-02-26 22:30:27 +01:00
project Enable more revive linter rules (#30608) 2024-04-28 15:39:00 +02:00
pull [GITEA] GetScheduledMergeByPullID may involve a system user 2024-02-05 16:09:41 +01:00
repo Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00
secret Make runs-on support variable expression (#29468) 2024-03-11 23:36:59 +07:00
shared/types Refactor locale&string&template related code (#29165) 2024-02-16 15:20:52 +01:00
system Refactor deletion (#28610) 2023-12-25 21:25:29 +01:00
unit Add a direct link from repo header to unit settings 2024-02-13 22:42:09 +01:00
unittest [CHORE] Remove Microsoft SQL Server Support 2024-04-05 23:37:36 +02:00
user Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00
webhook webhook: sourcehut_builds: ask for access_token instead of authorization_header 2024-04-16 08:59:55 +02:00
error.go Add merge style fast-forward-only (#28954) 2024-02-14 17:19:19 +01:00
fixture_generation.go Replace more db.DefaultContext (#27628) 2023-10-15 17:46:06 +02:00
fixture_test.go Replace more db.DefaultContext (#27628) 2023-10-15 17:46:06 +02:00
main_test.go make writing main test easier (#27270) 2023-09-28 01:38:53 +00:00
org.go Refactor deletion (#28610) 2023-12-25 21:25:29 +01:00
org_team.go Remove GetByBean method because sometimes it's danger when query condition parameter is zero and also introduce new generic methods (#28220) 2023-12-07 15:27:36 +08:00
org_team_test.go Reduce usage of db.DefaultContext (#27073) 2023-09-14 17:09:32 +00:00
org_test.go Replace more db.DefaultContext (#27628) 2023-10-15 17:46:06 +02:00
repo.go Refactor deletion (#28610) 2023-12-25 21:25:29 +01:00
repo_test.go Penultimate round of db.DefaultContext refactor (#27414) 2023-10-11 04:24:07 +00:00
repo_transfer.go chore: use errors.New to replace fmt.Errorf with no parameters will much better (#30621) 2024-04-28 15:39:00 +02:00
repo_transfer_test.go [MODERATION] User blocking 2024-02-05 15:56:45 +01:00