Yes, the performance would be worse.  Would you ever notice it?  I'd
seriously doubt it.  You mentioned running it in a cron job; you'd
never see the effects of the lowered performance.  The lack of added
complexity might be worth it--less code (in this case) means easier to
maintain.  If you're worried about performance, you could always
benchmark it--but I'd doubt it would make enough of a difference to
worry about.

On Nov 26, 9:11 am, "Alex Jillard" <[EMAIL PROTECTED]> wrote:
> Wouldn't that give me worse performance though?  Filtering the two lists
> verses making 300+ save()'s in a try/except, 90% of which won't be committed
> to the database?
>
> On Wed, Nov 26, 2008 at 9:00 AM, Jeff FW <[EMAIL PROTECTED]> wrote:
>
> > If you already have a unique key on the project's name field, then
> > you're good to go--no duplicates will ever get inserted.  No need to
> > do any filtering ahead of time--just put each save() in a try/except
> > block that catches the error you get and does nothing.
>
> > -Jeff
>
> > On Nov 25, 4:53 pm, "Alex Jillard" <[EMAIL PROTECTED]> wrote:
> > > Thanks for the replies Jeff and Rajesh.  I'll look int both of those
> > options
> > > and see what I can come up with.  My model is set to have the name of the
> > > project to be unique, so it was throwing an error if a duplicate was
> > added.
>
> > > Jeff, unfortunatly the initial list of CVS projects is just a string that
> > > I'm splitting, so I can't do it as I build that list.
>
> > > Thanks again
>
> > > On Tue, Nov 25, 2008 at 4:38 PM, Rajesh Dhawan <[EMAIL PROTECTED]
> > >wrote:
>
> > > > Hi Alex,
>
> > > > > Here is the code that I use.  Output_list is from CVS and
> > > > current_projects
> > > > > is from the database.  Is there a faster way to do this, or a built
> > in
> > > > > method in Python?  This code works fine now, but I can see it getting
> > > > slow.
>
> > > > > for b in output_list:
> > > > >         found = False
> > > > >         for i in current_projects:
> > > > >             if i.name == b:
> > > > >                 found = True
> > > > >         if not found:
> > > > >             new_projects.append(b)
>
> > > > Try converting the two project name lists into Python sets and take a
> > > > difference:
>
> > > > full_list = set(output_list)
> > > > db_list = set([i.name for i in current_projects])
> > > > new_projects = full_list - db_list
>
> > > > You should also add a unique=True attribute to your project.name
> > > > field.
>
> > > > -Rajesh D
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to