Skip to content

Commit d6b0bf5

Browse files
committed
fix: refresh Plex shared-server cache at start of user filter batches
Pass forceRefresh=true to getAllPlexUserIds() from the four batch entry points so each run reads the user's current Plex sharing settings rather than a snapshot left by the previous run. Fixes #577
1 parent a219582 commit d6b0bf5

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

server/lib/collections/plex/PlexUserManager.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,14 @@ export async function getSharedServers(
219219
/**
220220
* Get all Plex user IDs from shared servers (V2 API)
221221
* Returns array of Plex user IDs for all users with access to the server
222+
*
223+
* @param forceRefresh When true, bypass the shared-server cache and refetch
224+
* from Plex. Batch operations should pass true so that each run starts
225+
* from the user's current Plex state, not a snapshot from the previous run.
222226
*/
223-
export async function getAllPlexUserIds(): Promise<string[]> {
227+
export async function getAllPlexUserIds(
228+
forceRefresh = false
229+
): Promise<string[]> {
224230
try {
225231
const settings = getSettings();
226232
const admin = await getAdminUser();
@@ -235,7 +241,8 @@ export async function getAllPlexUserIds(): Promise<string[]> {
235241

236242
const sharedServers = await getSharedServers(
237243
settings.plex.machineId,
238-
admin.plexToken
244+
admin.plexToken,
245+
forceRefresh
239246
);
240247

241248
// V2 uses invitedId instead of userID
@@ -528,8 +535,10 @@ export async function applyPreSyncUserRestrictions(): Promise<void> {
528535
label: 'Plex User Manager',
529536
});
530537

531-
// Get all Plex users who need restrictions applied
532-
const allPlexUserIds = await getAllPlexUserIds();
538+
// Get all Plex users who need restrictions applied. Force a refresh so
539+
// this run reads the user's current Plex sharing settings rather than a
540+
// snapshot cached from the previous run.
541+
const allPlexUserIds = await getAllPlexUserIds(true);
533542
if (allPlexUserIds.length === 0) {
534543
logger.warn('No Plex users found - skipping user restrictions', {
535544
label: 'Plex User Manager',
@@ -603,8 +612,10 @@ export async function applySelectivePreSyncUserRestrictions(
603612
}
604613
);
605614

606-
// Get all Plex users who need restrictions applied
607-
const allPlexUserIds = await getAllPlexUserIds();
615+
// Get all Plex users who need restrictions applied. Force a refresh so
616+
// this run reads the user's current Plex sharing settings rather than a
617+
// snapshot cached from the previous run.
618+
const allPlexUserIds = await getAllPlexUserIds(true);
608619
if (allPlexUserIds.length === 0) {
609620
logger.warn('No Plex users found - skipping user restrictions', {
610621
label: 'Plex User Manager',

server/lib/collections/services/CollectionCleanupService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,9 @@ export class CollectionCleanupService {
298298
'@server/lib/collections/plex/PlexUserManager'
299299
);
300300

301-
const allPlexUserIds = await getAllPlexUserIds();
301+
// Force a refresh so this cleanup pass reads the user's current Plex
302+
// sharing settings rather than a stale snapshot from a previous run.
303+
const allPlexUserIds = await getAllPlexUserIds(true);
302304

303305
if (allPlexUserIds.length > 0) {
304306
logger.info(

server/lib/collections/services/CollectionSyncService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,8 +1125,9 @@ export class CollectionSyncService {
11251125
'@server/lib/collections/plex/PlexUserManager'
11261126
);
11271127

1128-
// Get all Plex users
1129-
const allPlexUserIds = await getAllPlexUserIds();
1128+
// Get all Plex users. Force a refresh so this cleanup pass reads the
1129+
// user's current Plex sharing settings rather than a stale snapshot.
1130+
const allPlexUserIds = await getAllPlexUserIds(true);
11301131
if (allPlexUserIds.length === 0) {
11311132
logger.debug('No Plex users found - skipping user filter cleanup', {
11321133
label: 'Collection Sync Service',

0 commit comments

Comments
 (0)