Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rules): Fixed an issue where the 'Plex - present in amount of oth… #804

Merged
merged 2 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions server/src/modules/api/lib/plexApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class PlexApi extends NodePlexAPI {
this.cache = cacheManager.getCache('plexguid');
}

async query<T>(options): Promise<T> {
return this.queryWithCache(options, true);
async query<T>(options, docache: boolean = true): Promise<T> {
return this.queryWithCache(options, docache);
}

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ class PlexApi extends NodePlexAPI {
return result as unknown as T;
}

async queryWithCache<T>(options, doCache: boolean): Promise<T> {
async queryWithCache<T>(options, doCache: boolean = true): Promise<T> {
if (typeof options === 'string') {
options = {
uri: options,
Expand Down
11 changes: 11 additions & 0 deletions server/src/modules/api/plex-api/plex-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { EPlexDataType } from './enums/plex-data-type-enum';
import axios from 'axios';
import PlexApi from '../lib/plexApi';
import PlexTvApi from '../lib/plextvApi';
import cacheManager from '../../api/lib/cache';

@Injectable()
export class PlexApiService {
Expand Down Expand Up @@ -237,6 +238,7 @@ export class PlexApiService {
public async getMetadata(
key: string,
options: { includeChildren?: boolean } = {},
useCache: boolean = true,
): Promise<PlexMetadata> {
try {
const response = await this.plexClient.query<PlexMetadataResponse>(
Expand All @@ -245,6 +247,7 @@ export class PlexApiService {
? '?includeChildren=1&includeExternalMedia=1&asyncAugmentMetadata=1&asyncCheckFiles=1&asyncRefreshAnalysis=1'
: ''
}`,
useCache,
);
if (response) {
return response.MediaContainer.Metadata[0];
Expand All @@ -260,6 +263,14 @@ export class PlexApiService {
}
}

public resetMetadataCache(mediaId: string) {
cacheManager.getCache('plexguid').data.del(
JSON.stringify({
uri: `/library/metadata/${mediaId}`,
}),
);
}

public async getDiscoverDataUserState(
metaDataRatingKey: string,
): Promise<any> {
Expand Down
4 changes: 2 additions & 2 deletions server/src/modules/rules/getter/plex-getter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export class PlexGetterService {
? metadata.Collection.filter(
(el) =>
el.tag.toLowerCase().trim() !==
(ruleGroup.manualCollectionName
? ruleGroup.manualCollectionName
(ruleGroup?.collection?.manualCollection
? ruleGroup.collection.manualCollectionName
: ruleGroup.name
)
.toLowerCase()
Expand Down
1 change: 1 addition & 0 deletions server/src/modules/rules/rules.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ export class RulesService {
rulegroupId: number,
mediaId: string,
): Promise<any> {
this.plexApi.resetMetadataCache(mediaId);
const mediaResp = await this.plexApi.getMetadata(mediaId);
const group = await this.getRuleGroupById(rulegroupId);
if (group && mediaResp) {
Expand Down
Loading