Skip to content

Commit

Permalink
Fill in lastReviewTime as the current time if it's not provided (#1392)
Browse files Browse the repository at this point in the history
It doesn't exist in the network data anymore.
  • Loading branch information
karashiiro authored Nov 25, 2024
1 parent b54e123 commit 7d58e3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,27 +152,6 @@ public void Behavior_DoesNotRun_WithInvalidStackSizeSales()
Assert.False(test.Behavior.ShouldExecute(upload));
}

[Theory]
[InlineData(0L)]
[InlineData(-1L)]
[InlineData(null)]
public void Behavior_DoesNotRun_WithInvalidReviewTimeListings(long? lastReviewTimeUnixSeconds)
{
var test = TestResources.Create();

var (listings, _) = SchemaSeedDataGenerator.GetUploadListingsAndSales(74, 5333);
listings[0].LastReviewTimeUnixSeconds = lastReviewTimeUnixSeconds;

var upload = new UploadParameters
{
WorldId = 74,
ItemId = 5333,
UploaderId = "5627384655756342554",
Listings = listings,
};
Assert.False(test.Behavior.ShouldExecute(upload));
}

[Fact]
public void Behavior_DoesNotRun_WithInvalidStackSizeListings()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,8 @@ public async Task<IActionResult> Execute(ApiKey source, UploadParameters paramet
return null;
}

private static bool IsInvalid(Universalis.Application.Uploads.Schema.Listing l)
private static bool IsInvalid(Schema.Listing l)
{
// Listings can be up for at most 7 days - checking against 8 to give some buffer
var lastReviewTimeUnixSeconds = l.LastReviewTimeUnixSeconds ?? 0;
var lastReviewTime = DateTimeOffset.FromUnixTimeSeconds(lastReviewTimeUnixSeconds).UtcDateTime;

// For some reason the first check wasn't enough to catch this
if ((DateTime.UtcNow - lastReviewTime).TotalDays >= 8 || lastReviewTimeUnixSeconds == 0 || lastReviewTime.Year < 2024)
{
return false;
}

return Util.HasHtmlTags(l.ListingId) || Util.HasHtmlTags(l.RetainerName) ||
Util.HasHtmlTags(l.RetainerId) || Util.HasHtmlTags(l.CreatorName) || Util.HasHtmlTags(l.SellerId) ||
Util.HasHtmlTags(l.CreatorId);
Expand Down Expand Up @@ -301,7 +291,7 @@ private static List<Listing> CleanUploadedListings(IEnumerable<Schema.Listing> u
DyeId = l.DyeId ?? 0,
CreatorId = Util.ParseUnusualId(l.CreatorId) ?? "",
CreatorName = l.CreatorName,
LastReviewTime = DateTimeOffset.FromUnixTimeSeconds(l.LastReviewTimeUnixSeconds ?? 0).UtcDateTime,
LastReviewTime = GetLastReviewTime(l),
RetainerId = Util.ParseUnusualId(l.RetainerId) ?? "",
RetainerName = l.RetainerName,
RetainerCityId = l.RetainerCityId ?? 0,
Expand All @@ -315,6 +305,14 @@ private static List<Listing> CleanUploadedListings(IEnumerable<Schema.Listing> u
.ToList();
}

private static DateTime GetLastReviewTime(Schema.Listing l)
{
var lastReviewTimeSeconds = l.LastReviewTimeUnixSeconds ?? 0;
return lastReviewTimeSeconds == 0
? DateTime.UtcNow
: DateTimeOffset.FromUnixTimeSeconds(lastReviewTimeSeconds).UtcDateTime;
}

private static List<Sale> CleanUploadedSales(IEnumerable<Schema.Sale> uploadedSales, int worldId, int itemId,
string uploaderIdSha256)
{
Expand Down

0 comments on commit 7d58e3e

Please sign in to comment.