Open Marchand-Nicolas opened 1 week ago
Hi, can I work on this?
I am applying to this issue via OnlyDust platform.
Hello @Marchand-Nicolas , I would like to fix this...
first, add last_question_id to AppState
pub_struct!(;AppState {
last_task_id: Mutex<i64>,
last_question_id: Mutex<i64>,
conf: Config,
provider: JsonRpcClient<HttpTransport>,
db: Database,
logger: Logger,
});
then, implement a get_next_question_id
that checks the Appstate and when the Appstate doesn't have a value (due to restart), we read the db
async fn get_next_question_id(
state: &AppState,
collection: &Collection<QuizQuestionDocument>,
) -> i64 {
let mut state_last_question_id = state.last_question_id.lock().await;
if *state_last_question_id == 0 {
// If the state value is 0, read from the database
*state_last_question_id = get_last_question_id(collection).await;
}
// Increment and return the next ID
*state_last_question_id += 1;
*state_last_question_id
}
async fn get_last_question_id(collection: &mongodb::Collection
match collection.find_one(None, options).await {
Ok(Some(doc)) => doc.id,
_ => 0, // If no documents found or error occurred, start from 0
}
}
- finally, update `/admin/tasks/quiz/question/create` endpoint to use `get_last_question_id`
```rs
let next_quiz_question_id = get_next_question_id(&state, &quiz_questions_collection).await;
ETA: 1 hrs.
I am applying to this issue via OnlyDust platform.
hello @ i'm an experienced frontend developer and a blockchain developer i would love to work on this issue Pleasee kindly assign :)
I am applying to this issue via OnlyDust platform.
Hello I'm a front-end and a blockchain developer and will love to work on this issue
I am applying to this issue via OnlyDust platform.
I'm a Full Stack Blockchain Developer with demonstrable expertise across modern web and blockchain technologies. My tech stack centers on Next.js, TypeScript, React, and Node.js for web development, complemented by Three.js for 3D experiences, and Solidity/Rust for blockchain solutions.
What sets me apart is my proven track record on OnlyDust, where I've made 83 significant contributions across 15 different projects since Edition 1. This extensive involvement reflects my ability to deliver quality solutions under tight deadlines while adapting to diverse project requirements.
With my deep experience in hackathon environments, I bring both technical excellence and practical development skills to the table. I'm confident I can contribute meaningfully to pushing the boundaries of what's possible in blockchain development while maintaining a focus on user-centric solutions.
My profile (https://app.onlydust.com/u/Ugo-X) showcases my consistent ability to deliver results across various blockchain challenges. I'm excited to bring this experience and drive for innovation to your team.
First, I'll add a last_question_id to the state struct - just like we have for tasks. Makes sense to keep them consistent.
Then for the ID generation:
Quick db check to get the latest question_id
Compare with what's in state
Use whichever is higher and add 1
Update state with new value
The state acts like a cache here - keeps things fast for bulk requests while the db check ensures we don't get out of sync after restarts.
Main thing is avoiding duplicate IDs while staying performant. Pretty standard race condition stuff.
I am applying to this issue via OnlyDust platform.
I am a Full Stack Developer specializing in Next.js, TypeScript, Node.js, Cairo and Rust . With over 31 contributions across projects in the OnlyDust ecosystem, I’ve developed strong proficiency in delivering high-quality solutions and resolving complex issues within tight deadlines. My experience spans frontend, backend, smart contracts, and the optimization and maintenance of scalable codebases.
I will fix the question IDs in the create_question.rs
file. The current implementation incorrectly sets the next_quiz_question_id
as the last_task_id + 1
. Instead, it should be based on the last_question_id + 1
. To address this, I will first retrieve the last question document from the database and collect its ID. Then, I will add a new last_question_id
field in the state, similar to how we handle the last_task_id
. By comparing the two IDs, I will ensure that we return the correct one for the next question.
It’s important to read from the database every time to maintain synchronization, especially since the state can be lost if the server restarts. However, I will also ensure that writing to the state happens to manage simultaneous requests effectively. This way, we can prevent multiple questions from having the same ID, maintaining the integrity of our quiz system.
I am applying to this issue via OnlyDust platform.
Hello, I'm Dprof-in-tech, a seasoned Full Stack Blockchain Developer, and I'm excited to be part of ODHACK 9! I have a strong foundation in technologies such as Next.js, TypeScript, JavaScript, React, Node.js, Rust, and Cairo, I've built extensive experience across the blockchain development landscape.
I first got involved with OnlyDust during Edition 2, and since then, I've made 39 contributions across 11 different projects. Working on the platform has really helped me sharpen my skills, especially when it comes to delivering great solutions under tight deadlines. I love combining technical know-how with a user-focused approach, whether it's building immersive 3D experiences or crafting smart contracts that solve real-world problems.
Throughout, I've consistently demonstrated the ability to adapt and contribute effectively to diverse challenges. I'm confident in my ability to tackle new problems and drive innovation within the blockchain space. As we kick off ODHACK 9, I'm eager to apply my previous experience and technical expertise to push the boundaries of what's possible.
You can view my public profile on OnlyDust here: https://app.onlydust.com/u/Dprof-in-tech
Here's my approach to fixing the question ID generation logic in Rust:
State Management Update: I’ll create a new field as specified to take the last question ID. I would also add this new field to the state so that the value of the last question ID can be accessible across the app.
ID Generation Logic:
Integration:
Testing Strategy:
Implementation Plan:
Key Considerations:
I am applying to this issue via OnlyDust platform.
I have a strong foundation in software engineering, particularly in developing web applications and working with various programming languages and technologies, including JavaScript, Node.js, Rust, and database management systems like MongoDB.
Understand Requirements: Begin by clarifying the requirements for generating unique quiz question IDs. Identify the need for synchronization between the database and the in-memory state.
Design State Management:
Extend the application state to include a last_question_id field. Use a mutex to safely manage access to this state in a concurrent environment. Implement Database Interaction:
Create a function to retrieve the last question ID from the database. This function will be called every time a new question is created to ensure accuracy. Implement error handling to manage potential failures during database access. Modify the ID Generation Logic:
In the handler, retrieve the last question ID from both the database and the state. Calculate the next question ID by taking the maximum of the last IDs from both sources and adding one. Testing and Validation:
Test the implementation under various conditions, including simultaneous requests, to ensure that the ID generation remains robust and consistent. Validate that the application behaves correctly when the server is restarted and the state is reset. Documentation:
Document the changes made, explaining the rationale behind the new logic for future reference and maintenance.
I am applying to this issue via OnlyDust platform.
Hi, I’m Mimi Sav, a frontend and blockchain developer. This is my first time contributing to this repository, and I'm excited about the opportunity to collaborate.
To address the issue regarding the calculation of the next_quiz_question_id in src/endpoints/admin/quiz/create_question.rs, I’ll implement the following steps:
Retrieve the Last Question ID: I'll modify the code to fetch the last question document from the database to get its ID instead of relying on the last_task_id. Add last_question_id Field: I’ll introduce a new field called last_question_id in the state to track the most recent question ID similarly to how last_task_id is managed. Compare and Determine Next ID: I’ll implement logic to compare the last_question_id from the state with the ID retrieved from the database. The greater value will determine the next_quiz_question_id. Update State Accordingly: After creating a new question, I'll update the state with the new last_question_id to ensure it reflects the most recent addition. Maintain Sync with the Database: By reading from the database each time, I’ll ensure that the state is always synchronized, especially in scenarios where the server is restarted, which could otherwise result in ID conflicts. Optimize for Concurrent Requests: Since reading from the database can be slow, the new state management will help prevent race conditions where multiple requests could lead to the creation of questions with the same ID.
I am applying to this issue via OnlyDust platform.
I'm a senior Full Stack Web3 Developer having contributed to several OD Hacks in the past.
I will fix the route as described in the issue which is pretty self-explanatory.
I am applying to this issue via OnlyDust platform.
Hi, I'm Collins a frontend and blockchain developer, and an active contributor on OnlyDust. You can check out my profile here: https://app.onlydust.com/u/0xdevcollins.
To address the issue regarding the next_quiz_question_id in src/endpoints/admin/quiz/create_question.rs, I will implement the following plan:
I will start by modifying the code to fetch the last question document from the database instead of relying on the last_task_id. This involves querying the database to retrieve the most recent question and collecting its ID. I will introduce a new field, last_question_id, in the state to store this value, similar to how last_task_id is handled.
Next, I will compare the last_question_id with the existing last_task_id to determine which one is newer. Based on this comparison, I will increment the relevant ID by one to generate the next_quiz_question_id.
I am applying to this issue via OnlyDust platform.
I am a python dev . A new-comer here, willing and ready to contribute to solve the issue.
In
src/endpoints/admin/quiz/create_question.rs
around line 68, it doesn't really makes sense: the next_quiz_question_id should not be the last_task_id + 1 but instead it should be the last_question_id + 1.Proposed to do:
last_question_id
field in the state (like we are doing for the last_task_id)Reading the db every time is important to make sure it's always synced, and also if we restart the server the state is lost. But writing in the state is also important, because when receiving simultaneous requests, reading to the db is too slow and we would end up with multiple questions having the same id.