Skip to content

Commit 22d2ba4

Browse files
authored
Fix photos appearing multiple times per-album in RSS feed (#4499)
1 parent 99c0ba1 commit 22d2ba4

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

app/Actions/RSS/Generate.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public function do(): Collection
107107
'photos.title',
108108
'photos.description',
109109
'photos.type',
110+
'photos.created_at',
110111
'photos.updated_at',
111112
'outer_' . PA::ALBUM_ID,
112113
'base_albums.title as album_title',
@@ -117,6 +118,7 @@ public function do(): Collection
117118
'users.display_name',
118119
]
119120
)
121+
->distinct()
120122
->where('photos.created_at', '>=', $now_minus)
121123
->limit($rss_max)
122124
->orderBy('photos.created_at', 'desc')

tests/Feature_v2/RssTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
namespace Tests\Feature_v2;
2020

2121
use App\Models\Configs;
22+
use App\Models\Photo;
2223
use App\Repositories\ConfigManager;
2324
use Exception;
2425
use Tests\Feature_v2\Base\BaseApiWithDataTest;
@@ -66,4 +67,42 @@ public function testRSS1(): void
6667
Configs::set('rss_enable', $init_config_value);
6768
}
6869
}
70+
71+
/**
72+
* A single photo (one row in `photos`) that belongs to two albums (two rows
73+
* in `photo_album`) must appear exactly once per album in the RSS feed.
74+
*/
75+
public function testRSSPhotoInMultipleAlbumsIsNotDuplicated(): void
76+
{
77+
$config_manager = resolve(ConfigManager::class);
78+
$init_config_value = $config_manager->getValue('rss_enable');
79+
80+
try {
81+
Configs::set('rss_enable', '1');
82+
83+
// One photo, two album memberships.
84+
$photo = Photo::factory()
85+
->owned_by($this->admin)
86+
->in($this->album1)
87+
->create();
88+
$photo->albums()->attach($this->album2->id);
89+
90+
$response = $this->actingAs($this->admin)->get('/feed');
91+
$this->assertOk($response);
92+
$content = $response->getContent();
93+
94+
// `<guid>` is rendered exactly once per feed item, so it is a reliable
95+
// per-item marker (the page link itself also appears in `<link>`).
96+
$guid_album1 = '<guid>' . route('gallery', ['albumId' => $this->album1->id, 'photoId' => $photo->id]) . '</guid>';
97+
$guid_album2 = '<guid>' . route('gallery', ['albumId' => $this->album2->id, 'photoId' => $photo->id]) . '</guid>';
98+
99+
// The photo is in two albums, so it must appear exactly once per album.
100+
$this->assertSame(1, substr_count($content, $guid_album1), 'photo should appear once for album1');
101+
$this->assertSame(1, substr_count($content, $guid_album2), 'photo should appear once for album2');
102+
} catch (\Exception $e) {
103+
$this->assertTrue(false, 'Exception occurred: ' . $e->getMessage());
104+
} finally {
105+
Configs::set('rss_enable', $init_config_value);
106+
}
107+
}
69108
}

0 commit comments

Comments
 (0)