Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8166623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:56:24+00:00 2026-06-06T19:56:24+00:00

1) The controller code (Symfony2 framework): $em = $this->getDoctrine()->getEntityManager(); // get latest toplist $last

  • 0

1) The controller code (Symfony2 framework):

    $em = $this->getDoctrine()->getEntityManager();

    // get latest toplist
    $last = $em->getRepository('RadioToplistBundle:Toplist')->findOneBy(
      array('number' => 'DESC')
    );

    // get current year and week of the year
    $week = date('W');
    $year = date('Y');

    // if:
    //   [case 1]: $last is null, meaning there are no toplists in the database
    //   [case 2]: $last->getYear() or $last->getWeek() do not match current
    //             year and week number, meaning that there are toplists in the
    //             database, but not for current week
    // then:
    //   create new toplist entity (for current week of current year)
    // else:
    //   do nothing (return)

    if($last && $last->getYear() == $year && $last->getWeek() == $week)
      return;
    else {
      $new = new Toplist();
      $new->setYear($year);
      $new->setWeek($week);
      $em->persist($new);
      $em->flush();
    }

This code is executed with each request to view toplist results (frontend) or list of toplists (backend). Anytime someone wants to access the toplist we first check if we should create a new toplist entity (for new week).

2) The question is:

Is it possible that:

  • User A goes to mydomain.com/toplist at 00:00:01 on Monday -> the code should generate new entity
  • the server slows down and it takes him 3 seconds to execute the code
  • so new toplist entity is saved to database at 00:00:04 on Monday
  • User B goes to mydomain.com/toplist at 00:00:02 on Monday
  • at 00:00:02 there the toplist is not yet saved in database, thus UserB’s request triggers the code to create another toplist entity

And so.. after a few seconds we have 2 toplist entities for current week.

Is this possible?

How should I prevent this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:56:26+00:00Added an answer on June 6, 2026 at 7:56 pm

    Yes, it is possible. You should use locks while performing calculations based on db values (which are than stored back in the db).

    Read more on locks in doctrine’s docs: Locking support

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this controller in Code Igniter application. A value is initialized in the
I have this controller in Code Igniter that begins with class MyController extends CI_Controller
I'm try something from this comment idea Code Igniter Controller/Model name conflicts find class
I'm trying to reorganize some controller code into .js.erb jquery files. (Warning, this is
$(#frmCompose).submit(function () { $(this).ajaxSubmit({ success: function (response) { alert('success'); } }); }); Controller code:
This is my controller code: using (var db = new MatchGamingEntities()) { var MyMatches
This is my session's controller code def create user = User.authenticate(params[:login], params[:password]) if user
This is a strange one, I have everything working but in the controller code
I have the controller code as follows: $form_company=new Project_Form_AddCompany(); $this->view->form=$form_company; $form_company->setAction('add-Company'); if ($this->_request->isPost()) {
Here is my controller code for displaying.. $this->layout = 'admin-home'; $studios = AccountsStudios::model()->with('generalUserStudiosesCount')->findAll(); #print_r($studios);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.