Skip to content

Conversation

Copy link

Copilot AI commented Nov 10, 2025

The addProduct method created a FoodItem object that was never persisted—only a separately constructed foodItemData map was written to Firestore. This caused unnecessary object allocation and obscured which data structure was actually being stored.

Changes

  • Removed premature FoodItem instantiation before Firestore write
  • Construct FoodItem only after successful persistence, using the generated document ID
  • Use method parameters directly in appendToCsv call instead of referencing unused object

Before:

val foodItem = FoodItem(...)  // Created but never persisted
val foodItemData = mutableMapOf(...)  // This is what actually gets stored

firestore.collection("foodItems").add(foodItemData)
    .addOnSuccessListener { ref ->
        // Use foodItem.copy() to add the ID
        onSuccess(foodItem.copy(id = ref.id, daysDifference = daysDifference))
    }

After:

val foodItemData = mutableMapOf(...)  // Single source of truth for persistence

firestore.collection("foodItems").add(foodItemData)
    .addOnSuccessListener { ref ->
        val foodItem = FoodItem(id = ref.id, ...)  // Built from persisted values
        onSuccess(foodItem)
    }

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

The FoodItem object was being created before persisting to Firestore, but the
actual persisted data came from foodItemData map. This created unnecessary
object instantiation and potential confusion. Now FoodItem is only created
after successful persistence with the actual document ID.

Co-authored-by: maxschwinghammer <111356450+maxschwinghammer@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 10, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.13-bin/5xuhj0ry160q40clulazy9h7d/gradle-8.13/lib/gradle-daemon-main-8.13.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.13-bin/5xuhj0ry160q40clulazy9h7d/gradle-8.13/lib/agents/gradle-instrumentation-agent-8.13.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.13 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] WIP Address feedback on storing barcode usage Remove unnecessary FoodItem instantiation before Firestore persistence Nov 10, 2025
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.

2 participants