Skip to content

Commit

Permalink
Merge pull request #121 from se1exin/chore_chaos_env
Browse files Browse the repository at this point in the history
chore: adding chaos env that makes cleanarr show all non duplicates instead of duplicates
  • Loading branch information
peter-mcconnell authored Nov 7, 2023
2 parents 9bd2fbb + 5c71e3c commit 34df70e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 8 additions & 3 deletions backend/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# be invoked directly with ./backend/benchmark.py to simply run get_dupe_content()
# and print traces to stdout (note: traces only available if DEBUG=1 set)

import os
import pytest
import time
from plexwrapper import PlexWrapper
Expand All @@ -14,14 +15,18 @@

load_dotenv()

def get_dupe_content():
PlexWrapper().get_dupe_content()
def get_dupe_content(page):
return PlexWrapper().get_dupe_content(int(page))

def test_get_dupe_content(benchmark):
benchmark.pedantic(get_dupe_content, iterations=10, rounds=3)


# allow for direct invocation, without pytest
if __name__ == "__main__":
get_dupe_content()
dupes = get_dupe_content(os.getenv("PAGE", "1"))
if dupes:
print(f"found {len(dupes)} dupes")
else:
print("no data found ...")
print_top_traces(10)
10 changes: 8 additions & 2 deletions backend/plexwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def get_dupe_content_for_section(self, page, section):
if section.type not in ("movie", "show"):
return {}
dupes = []
duplicate=True
# undocumented environment variable purely for development purposes.
# instead of looking for duplicates, this will look for non-duplicates
# which can be useful when wanting to test the UI against a larger dataset
if os.getenv("CHAOS_NOT_DUPLICATE", "0") == "1":
duplicate=False
to_dict_func = self.movie_to_dict
if section.type == "episode":
to_dict_func = self.episode_to_dict
Expand All @@ -101,9 +107,9 @@ def get_dupe_content_for_section(self, page, section):
libtype = section.type
if libtype == "show":
libtype = "episode"
results = section.search(duplicate=True, libtype=libtype, container_start=offset, limit=limit)
results = section.search(duplicate=duplicate, libtype=libtype, container_start=offset, limit=limit)
for item in results:
if len(item.media) > 1:
if not duplicate or len(item.media) > 1:
future = executor.submit(to_dict_func, item, section.title)
futures.append(future)

Expand Down

0 comments on commit 34df70e

Please sign in to comment.