Skip to content

Shadowing: use DTO's #2331

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

Merged
merged 20 commits into from
Mar 13, 2024
Merged

Shadowing: use DTO's #2331

merged 20 commits into from
Mar 13, 2024

Conversation

nickygerritsen
Copy link
Member

This should have (almost) no functional changes, but it uses DTO's for reading from the event feed, making it that we can get rid of a lot of array shapes and that we get added type safety.

I did add the provider object to the API root endpoint, so we can reuse it here and added some small improvements, see the separate commits.

@nickygerritsen nickygerritsen changed the title Shadow differences: redirect to configure page if not set up yet. Shadowing: use DTO's Feb 15, 2024
Copy link
Member

@vmcj vmcj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good enough to merge as is, there are some discussion points left for future PRs.


class Award implements EventData
{
// Not used currently, so no fields
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does the class exist then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise we need special checks for unknown events. This makes the code a bit cleaner

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you prefer to add the special cases to the ExternalContestSourceService?

public readonly ?string $scoreboardFreezeDuration,
public readonly int $penaltyTime,
public readonly ?string $startTime,
// TODO: check for end time and scoreboard thaw time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to resolve before merging?

Copy link
Member Author

@nickygerritsen nickygerritsen Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. @vmcj wanted this comment. It would be a new “feature”


class TeamMember implements EventData
{
// Not used currently, so no fields
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, is it necessary?

bool $fromStart,
array $eventsToSkip,
?callable $progressReporter = null
): bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this is the same change as in #2343 so I suppose that PR indeed contains duplicate commits.

Also, like my comment there: can we please not do reformatting of code that is not otherwise touched by your changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. I am very used to (at work) reformat a file with a code style before saving to make it in sync.
I will try to undo all these reformat changes (even though they don't adhere to the code style).

$freezeHour = floor($freezeStartSeconds / 3600);
$freezeMinutes = floor(($freezeStartSeconds % 3600) / 60);
$freezeSeconds = floor(($freezeStartSeconds % 60) / 60);
$freezeMilliseconds = $freezeStartSeconds - floor($freezeStartSeconds);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with this kind of removal of alignment spaces. It makes the code less readable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, this is what the code style currently says. I will undo these changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know exactly what the current code style says, but I strongly think that automatic reformatting of alignment like this should be removed from it. Code formatting is a means to an end (better readability of code) and not a goal in itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the problem is it wants some alignment and you can’t say “do whatever there was” but I hope I’m wrong since that would save me time


$eventType = EventType::fromString($data['type']);
if ($this->getEventFeedFormat($data, $context) === EventFeedFormat::Format_2022_07) {
$operation = !isset($data['data']) ? Operation::DELETE : Operation::CREATE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$operation = !isset($data['data']) ? Operation::DELETE : Operation::CREATE;
$operation = isset($data['data']) ? Operation::CREATE : Operation::DELETE;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's more readable?

@nickygerritsen
Copy link
Member Author

@vmcj found an issue with legacy delete events. I will fix that but before doing that add tests for some events so we know they are parsed correctly.

{
$hash = ExternalSourceWarning::calculateHash($type, $entityType, $entityId);
$warning = $this->em
$hash = ExternalSourceWarning::calculateHash($type, $eventType->value, $entityId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you touch this in your PR or if it was already broken but calculateHash expects a string for $entityId but that can be null

@nickygerritsen nickygerritsen force-pushed the shadow-dto branch 2 times, most recently from 29397c1 to 044b085 Compare February 28, 2024 12:16
@nickygerritsen nickygerritsen added this pull request to the merge queue Mar 13, 2024
Merged via the queue into DOMjudge:main with commit 440cfa2 Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants