Hi ...

so I'll just go over to this thread  with my problems :)

Grigri, your code worked perfectly, drop the paste into behaviours,
add

    var $actsAs = array('List'=>
                    array(
                        'scope'=>'jobcolumn_id',
                        'column'=>'jobcolumn_position',
                        ));

or so to the model and you are sorted. Jobcolumn_id is a foreign
key...I have a lot of jobs in various columns sorted by
jobcolumn_position.

What I've been wrapping my head around is getting the thing thread
safe for a large number of entries. Sounds very simple, I know, but
somehow it isn't for me.

With your code, I manage to break the sequence quite easily by running
my test program twice at the same time. The test program moves the
jobs from one jobcolumn_id to the other, appends the job to the end of
the new column and updates the positions in the old column (all of
which is handles by the behaviour).

When I run this test simultaneously on two browser I get a duplicate
key error from mysql quite quickly.

I managed to fixit a bit  by adding

function beforeSave()
{
        $this->query("LOCK TABLE {$this->table} AS Framejob WRITE,
{$this->table} WRITE,
                        queues AS Queue WRITE,jobcolumns as Jobcolumn
WRITE,storages as Storage WRITE,
                        lenscolors as Lenscolor WRITE,framecolors as
Framecolor WRITE,names as Name WRITE");
}

// the locks on all the tables are required because of cake's joins
during the update query

and

function afterSave()
{
     $this->query("UNLOCK tables");
}

With this I can move jobs about a few 100 times but eventually I also
get a MySQL error.

Any idea what to do? I tried out the transaction behaviour but I think
the problem occurs like this

Thread B: Get MAX jobcolumns_position from column 1 -> Next free pos
is 25
Thread A: Get MAX jobcolumns_position from column 1 -> Next free pos
is 25
Thread B: update job so it is in column 1 now, jobcolumn_position is
25
Thread A: update job so it is in column 1 now, jobcolumn_position is
25 <- Bang, duplicate key column 1, jobcolumn_position 25

So the transaction would only help if the error occured during the
position = position -1 query ... or am I wrong about that?

Thanks again for your help

flow




On 12 Feb., 10:46, grigri <[EMAIL PROTECTED]> wrote:
> > I tried the grigri stuff too but it didn't quite work.
>
> Could you be more specific as to _how_ it didn't quite work? Was some
> functionality you expected missing, or did it not work in a way you
> expected? I don't know RoR so I've no basis for comparaison in that
> respect.
>
> I use that code in a lot of (admittedly small) projects, and although
> it fits my needs, if you can suggest improvements/enhancements, I'd be
> glad to hear them. But "it didn't quite work" doesn't really give me a
> lot to work with.
>
> On Feb 12, 2:23 am, Baz <[EMAIL PROTECTED]> wrote:
>
> > Sometimes it's hard to really "read" email/posts.
>
> > As I said, CakePHP has helped me a lot, and since I'm not a great
> > coder, I'm trying to give back in anyway I can.
>
> > On Feb 11, 2008 8:16 PM, nate <[EMAIL PROTECTED]> wrote:
>
> > > That didn't seem sarcastic to me at all, but maybe you thought that
> > > because that's becoming part of a pervasive attitude around here.  If
> > > that's the case, we need to fix that.
>
> > > Baz, you make some good points.  If you're interested, you and I can
> > > have an offline discussion about drafting some sort of conduct policy
> > > along the lines of your suggestions.
>
> > > On Feb 11, 8:05 pm, Baz <[EMAIL PROTECTED]> wrote:
> > > > Hey, I was just trying to help. CakePHP has opened a lot of doors for
> > > > me, but I personally think that the process could be a lil' less
> > > > painful.
>
> > > > On Feb 11, 2008 6:43 PM, DragonI <[EMAIL PROTECTED]> wrote:
>
> > > > > Baz,
>
> > > > > You've hit the nail on the head from both ends :) You should post this
> > > > > on your blog.
>
> > > > I sense sarcasm, but I can't exactly be sure...
>
> > > > > The result will be novices/newbies will just say screw it and move on
> > > > > to another more friendly community. The seasoned cakers will get
> > > > > frustrated and stop helping/mentoring. This is absolutely lose lose
> > > > > situation.
>
> > > > The result of what, my suggestions?
>
> > > > > The lessons I've learned over time is that no matter how good your
> > > > > product is, if no one can use it then your product fails. Just look at
> > > > > all of the database companies who have come and gone. My corporate
> > > > > friends are MS SQL server freaks who love it because MS made it easier
> > > > > to use/admin then it's father - Sybase. So look at where Sybase is
> > > > > today compared to MS.
>
> > > > So is there a proposal here?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to