Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

fix: modify updateProgress function to handle timeout issues #334

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
10 changes: 5 additions & 5 deletions Jellyfin.Plugin.Themerr.Tests/TestThemerrController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@
var result = _controller.GetProgress();
Assert.IsType<JsonResult>(result);

// ensure result["media_count"] is an int
// ensure the following properties are int
Assert.IsType<int>(((JsonResult)result).Value?.GetType().GetProperty("media_count")?.GetValue(((JsonResult)result).Value, null));

// ensure result["media_percent_complete"] is an int
Assert.IsType<int>(((JsonResult)result).Value?.GetType().GetProperty("media_percent_complete")?.GetValue(((JsonResult)result).Value, null));
Assert.IsType<int>(((JsonResult)result).Value?.GetType().GetProperty("media_with_themes")?.GetValue(((JsonResult)result).Value, null));
Assert.IsType<int>(((JsonResult)result).Value?.GetType().GetProperty("total_pages")?.GetValue(((JsonResult)result).Value, null));

// ensure result["items"] is an array list
Assert.IsType<ArrayList>(((JsonResult)result).Value?.GetType().GetProperty("items")?.GetValue(((JsonResult)result).Value, null));

// ensure int values are 0
Assert.Equal(0, ((JsonResult)result).Value?.GetType().GetProperty("media_count")?.GetValue(((JsonResult)result).Value, null));
Assert.Equal(0, ((JsonResult)result).Value?.GetType().GetProperty("media_percent_complete")?.GetValue(((JsonResult)result).Value, null));
Assert.Equal(0, ((JsonResult)result).Value?.GetType().GetProperty("media_with_themes")?.GetValue(((JsonResult)result).Value, null));
Assert.Equal(0, ((JsonResult)result).Value?.GetType().GetProperty("total_pages")?.GetValue(((JsonResult)result).Value, null));

// ensure array list has no items
Assert.Equal(0, (((JsonResult)result).Value?.GetType().GetProperty("items")?.GetValue(((JsonResult)result).Value, null) as ArrayList)?.Count);

// todo: add tests for when there are items

Check warning on line 77 in Jellyfin.Plugin.Themerr.Tests/TestThemerrController.cs

View workflow job for this annotation

GitHub Actions / build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)

Check warning on line 77 in Jellyfin.Plugin.Themerr.Tests/TestThemerrController.cs

View workflow job for this annotation

GitHub Actions / build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
}

/// <summary>
Expand Down
23 changes: 13 additions & 10 deletions Jellyfin.Plugin.Themerr/Api/ThemerrController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,30 @@ public async Task TriggerUpdateRequest()
/// "media_percent_complete": ThemedItems.Count / BaseItems.Count * 100,
/// }
/// </summary>
/// <param name="page">The page number to return.</param>
/// <param name="pageSize">The number of items to return per page.</param>
/// <returns>JSON object containing progress data.</returns>
[HttpGet("GetProgress")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult GetProgress()
public ActionResult GetProgress(int page = 1, int pageSize = 10)
{
var tmpItems = new ArrayList();

var mediaCount = 0;
var mediaWithThemes = 0;
var mediaPercentComplete = 0;

var items = _themerrManager.GetTmdbItemsFromLibrary();

// sort items by name, then year
var enumerable = items.OrderBy(i => i.Name).ThenBy(i => i.ProductionYear);
var enumerable = items.OrderBy(i => i.Name).ThenBy(i => i.ProductionYear).ToList();

foreach (var item in enumerable)
// calculate total media count before applying pagination
var totalMediaCount = enumerable.Count;

// apply pagination
var pagedItems = enumerable.Skip((page - 1) * pageSize).Take(pageSize);

foreach (var item in pagedItems)
{
var year = item.ProductionYear;
var issueUrl = _themerrManager.GetIssueUrl(item);
Expand All @@ -125,16 +132,12 @@ public ActionResult GetProgress()
}
}

if (mediaCount > 0)
{
mediaPercentComplete = (int)Math.Round((double)mediaWithThemes / mediaCount * 100);
}

var tmpObject = new
{
items = tmpItems,
media_count = mediaCount,
media_percent_complete = mediaPercentComplete,
media_with_themes = mediaWithThemes,
total_pages = (int)Math.Ceiling((double)totalMediaCount / pageSize),
};

_logger.LogInformation("Progress Items: {Items}", JsonConvert.SerializeObject(tmpObject));
Expand Down
Loading
Loading