lfglabs-dev / starknet.quest

The on-chain quest tool of Starknet
https://starknet.quest
31 stars 86 forks source link

Fix duplicate task IDs #838

Open Marchand-Nicolas opened 6 days ago

Marchand-Nicolas commented 6 days ago

Description

Fix: we often create new tasks in a batch. This is currently a problem because as the backend receives all these requests, it assigns the tasks IDs simultaneously, which causes multiples tasks to have the same ID (where every ID should be unique, and should, when adding a new task, be the last task ID + 1).

PROPOSED TODO

The issue is located here: app\admin\quests\dashboard\[questId]\page.tsx

const handleAddTasks = useCallback(async (addedTasks: StepMap[]) => {
    const taskPromises = addedTasks.map(async (step) => {
      if (step.type === "Quiz") {
        ...

      if (step.type === "TwitterFw") {
        ...
      } else if (step.type === "TwitterRw") {
      ...
Iwueseiter commented 6 days ago

can I work on this @Marchand-Nicolas? I'm a frontend and smart contract developer. To fix this bug, I will replace the addedTasks.map with a for...of loop to ensure that each request is awaited before moving to the next one. This approach ensures that each task is processed sequentially, preventing simultaneous ID assignments. The for...of loop combined with await will wait for each request to resolve before continuing to the next one. ETA: 24hrs.

onlydustapp[bot] commented 6 days ago

Hi @Iwueseiter! Maintainers during the ODHack # 8.0 will be tracking applications via OnlyDust. Therefore, in order for you to have a chance at being assigned to this issue, please apply directly here, or else your application may not be considered.

onlydustapp[bot] commented 6 days ago

Hi @Iwueseiter! Maintainers during the ODHack # 8.0 will be tracking applications via OnlyDust. Therefore, in order for you to have a chance at being assigned to this issue, please apply directly here, or else your application may not be considered.

martinvibes commented 3 days ago

hello @Marchand-Nicolas i'm a frontendand blockchain developerwith experience

To solve this issue i would simply use the for of loop instead of map to ensures that the request for each task is completed before the next one starts and i will also add try and catch incase of errors

please i would love to take on this issue by the time the od hack starts and get it done asap

onlydustapp[bot] commented 3 days ago

Hi @martinvibes! Maintainers during the ODHack # 8.0 will be tracking applications via OnlyDust. Therefore, in order for you to have a chance at being assigned to this issue, please apply directly here, or else your application may not be considered.

onlydustapp[bot] commented 2 days ago

Hi @vickiddev! Maintainers during the ODHack # 8.0 will be tracking applications via OnlyDust. Therefore, in order for you to have a chance at being assigned to this issue, please apply directly here, or else your application may not be considered.

coxmars commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I'm a software developer with 2+ years of experience and I have worked with backend technologies such as Cairo, Java, C# and frontend with React, NextJS, JS/TS. Also, I'm a member of the Dojo Coding community here in CR and I have made contributions in Cairo VM Go, Cairo VM TS, Cairo Lints etc.

How I plan on tackling this issue

1- I’ll review the current implementation in page.tsx, focusing on the handleAddTasks function and how task IDs are being assigned. 2- I’ll replace the addedTasks.map with a for loop to ensure each request is processed sequentially, preventing simultaneous ID assignment issues. 3- I’ll test the solution by creating new tasks in batches and verifying that each task receives a unique, incremented ID without duplicates. 4- Finally, I’ll ensure the changes are consistent with the rest of the codebase and follow best practices.

DiegoB1911 commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I'm a Full Stack Developer with two years of experience, primarily in Next.js. I'm also an active member of Dojo Coding, where I'm expanding my expertise in Cairo and Web3 technologies. I'm enthusiastic about learning, contributing, and becoming a part of this project.

How I plan on tackling this issue

To solve this issue, I would:

Understand the current implementation: First, I would review the existing code in app/admin/quests/dashboard/[questId]/page.tsx to understand how tasks are currently created and where the ID assignment process occurs.

Implement a sequential processing approach: I would replace the addedTasks.map method with a for loop. This change will ensure that each task creation request is sent sequentially, allowing the backend to respond before the next request is initiated. By doing this, we can prevent simultaneous ID assignment, ensuring that each task ID is unique and follows the correct order.

Document the implementation: Finally, I would document the implementation to explain the changes made and the reasoning behind using a sequential approach for task creation.

MatiasAchucarro commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a passionate and results-driven web developer, currently deepening my knowledge in web3 technologies, Cairo, and open-source development through Dojo Coding. My skill set includes expertise in JavaScript, React, HTML, CSS, and C# with .NET Entity Framework, among others. I also have experience with tools like Git, GitHub, SQL Server, and Postman. My focus has been on building solid web applications, from task lists to full-fledged CRUD systems, with front-end, back-end, and database integration. I have already made a contribution to Starknet Quest, and I am eager to take on more opportunities

How I plan on tackling this issue

To resolve the simultaneous identifier assignment issue when creating tasks in batches, I would modify the handleAddTasks function in page.tsx. Instead of using addedTasks.map, I would implement a for...of loop to process each task sequentially.

This change involves replacing addedTasks.map(async (step) => {...}) with for (const step of addedTasks) {...} and using await on each task creation call within the loop to ensure that each request completes before proceeding to the next. This adjustment will prevent identifier collisions, ensuring each task receives a unique ID based on the last assigned ID.

Iwueseiter commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I'm a frontend and smart contract developer. I've contributed to Projects here on onlydust and with that experience, I would handle this task as expected.

How I plan on tackling this issue

can I work on this @Marchand-Nicolas? I'm a frontend and smart contract developer. To fix this bug, I will replace the addedTasks.map with a for...of loop to ensure that each request is awaited before moving to the next one. This approach ensures that each task is processed sequentially, preventing simultaneous ID assignments. The for...of loop combined with await will wait for each request to resolve before continuing to the next one. ETA: 24hrs.

pheobeayo commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a web3frontend developer skilled in Javascript, Typescript, Solidity, Cairo and Rust.

How I plan on tackling this issue

-I will read through the contracts and understand the functions

deeseeker commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hi, I'm Qudus Adeyemi, a front-end developer with 2 years of experience. I had the opportunity to contribute to the previous OD Hackathon, where I improved the Starknet React documentation and developed a useWatchAssets hook to enhance wallet tracking functionalities. I enjoy learning and tackling new challenges, and I see this issue as a great way to deepen my understanding of Web3 technologies while contributing to the Starknet Quest project.

For issue #838, I estimate it will take around 1-2 days to complete, and I'm excited to dive into the task and collaborate with the team!

How I plan on tackling this issue

This is how I would tackle this issue:

Clone the project on my local machine and ensure it runs by following the provided documentation. Review the codebase to understand its structure and Locate the issue in app\admin\quests\dashboard[questId]\page.tsx. Leverage my previous experience with React Query, as I've encountered similar issues in past projects, to address the problem. Implement the fix based on my findings and knowledge. Test thoroughly to ensure the issue is resolved. Document the solution.

Benjtalkshow commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hi @Marchand-Nicolas,

I’m Benjamin, a JavaScript developer with 4 years of experience and over 18 contributions on OnlyDust | https://app.onlydust.com/u/Benjtalkshow. I’ve come across an issue with how task IDs are assigned when creating new tasks in batches, and I’m ready to help fix it.

How I plan on tackling this issue

Currently, when multiple tasks are created at once, the backend assigns IDs simultaneously, which leads to some tasks ending up with the same ID. Since every task should have a unique ID, this can create a bit of a mess, especially when we expect the new task ID to simply be the last one + 1.

To tackle this, I suggest we replace the use of addedTasks.map with a for loop. By doing this, we can process each request one at a time, ensuring that the task IDs are assigned correctly without overlap.

I’ve pinpointed where this issue is happening in the code at app\admin\quests\dashboard[questId]\page.tsx, and I’m ready to dive in and make these adjustments. I truly believe this change will enhance the reliability of our task management system.

EnochScript commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a frontend developer with expertise in JavaScript and react. This is my first time contributing to open source and I will like the opportunity to contribute to this project. I have good technical knowledge, I have the ability to work under pressure and adapt quickly and these will help me to contribute effectively to solving diverse challenges.

How I plan on tackling this issue

a. Sequential Task Creation: To prevent simultaneous ID assignment, I will refactor the task creation process to ensure that tasks are created one at a time, in sequence. Rather than sending all task creation requests in parallel, I will utilize a for...of loop in JavaScript to handle each task request sequentially. This approach allows each task to be processed and assigned an ID before the next task request is made. b. Using await to Control Task Flow: By using await with each task request, I will ensure that the system waits for the backend to respond (and assign a unique ID to the task) before proceeding to the next task. This prevents race conditions where multiple tasks are assigned the same ID at the same time.

onlydustapp[bot] commented 1 day ago

The maintainer Marchand-Nicolas has assigned deeseeker to this issue via OnlyDust Platform. Good luck!