Skip to content

Optimize code patterns from recent commits: eliminate duplication, modernize syntax, fix async handling#7

Merged
PhantomDave merged 2 commits intomainfrom
copilot/review-unoptimized-commits
Nov 10, 2025
Merged

Optimize code patterns from recent commits: eliminate duplication, modernize syntax, fix async handling#7
PhantomDave merged 2 commits intomainfrom
copilot/review-unoptimized-commits

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 10, 2025

Code review of today's commits revealed several suboptimal patterns: duplicate object mapping, redundant null coalescing, outdated C# syntax, missing async/await, and unnecessary computed wrappers.

Changes

Frontend - Eliminate duplication in FinanceRecordService

  • Extract repeated object mapping logic into mapToFinanceRecord() helper (~20 lines removed)
// Before: duplicate mapping in two places
if (result) {
  this._selectedFinanceRecord.set({ id: result.data?.createFinanceRecord.id ?? 0, ... });
  this._financeRecords.update(prev => [...prev, { id: result.data?.createFinanceRecord.id ?? 0, ... }]);
}

// After: single source of truth
if (result?.data?.createFinanceRecord) {
  const newRecord = this.mapToFinanceRecord(result.data.createFinanceRecord);
  this._selectedFinanceRecord.set(newRecord);
  this._financeRecords.update(prev => [...prev, newRecord]);
}

Frontend - Remove redundant null coalescing

  • Backend already defaults recurrenceFrequency to None, removed ?? RecurrenceFrequency.NONE

Backend - Modernize string slicing

  • Replace trimmed.Substring(0, 500) with range operator trimmed[..500]

Frontend - Fix missing await in ConfiguratorComponent

  • Add await to createFinanceRecord() call for proper async handling

Frontend - Remove unnecessary computed wrapper

  • Direct signal usage instead of computed(() => signal()) pass-through

Build - Support local schema in codegen

  • Add USE_LOCAL_SCHEMA env var to build without running GraphQL server
Original prompt

Do a review of the commits made today and see what is done in a wierd/unoptimized way


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…yntax

Co-authored-by: PhantomDave <34485699+PhantomDave@users.noreply.github.com>
Copilot AI changed the title [WIP] Review commits for optimization opportunities Optimize code patterns from recent commits: eliminate duplication, modernize syntax, fix async handling Nov 10, 2025
Copilot AI requested a review from PhantomDave November 10, 2025 16:45
@PhantomDave PhantomDave marked this pull request as ready for review November 10, 2025 20:49
Copilot AI review requested due to automatic review settings November 10, 2025 20:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes code patterns from recent commits by eliminating duplication, modernizing syntax, and fixing async handling issues.

  • Extracts repeated object mapping logic in FinanceRecordService into a reusable helper method
  • Modernizes C# string slicing syntax and removes redundant null coalescing
  • Fixes async/await handling in dialog callback and removes unnecessary computed wrapper

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
frontend/src/app/models/finance-record/finance-record-service.ts Extracts mapToFinanceRecord() helper to eliminate ~20 lines of duplicate mapping logic; removes redundant null coalescing for recurrenceFrequency
frontend/src/app/components/configurator/configurator-component/configurator-component.ts Adds await to createFinanceRecord() call in dialog callback for proper async handling
frontend/src/app/components/configurator/add-entry/add-entry.ts Removes unnecessary computed() wrapper by directly using toSignal() for isSubmitDisabled
frontend/codegen.ts Adds USE_LOCAL_SCHEMA environment variable support for local GraphQL schema building
PhantomDave.BankTracking.Api/Services/FinanceRecordService.cs Modernizes string slicing from Substring(0, 500) to range operator [..500]

description: string;
amount: number;
currency: string;
date: any;
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

The date parameter type should be string instead of any since GraphQL returns ISO date strings. This provides better type safety and makes the conversion on line 75 more explicit.

Suggested change
date: any;
date: string;

Copilot uses AI. Check for mistakes.
Comment on lines +60 to +68
private mapToFinanceRecord(data: {
id: number;
name: string;
description: string;
amount: number;
currency: string;
date: any;
isRecurring: boolean;
}): FinanceRecord {
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider extracting the inline type definition for the data parameter into a separate type or interface (e.g., CreateFinanceRecordResponse). This would improve reusability if the mapping needs to be used elsewhere and make the type definition more maintainable.

Copilot uses AI. Check for mistakes.
@PhantomDave PhantomDave merged commit 297fd53 into main Nov 10, 2025
9 of 11 checks passed
@PhantomDave PhantomDave deleted the copilot/review-unoptimized-commits branch November 10, 2025 21:09
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.

3 participants