• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Some help with Optimization
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Some help with Optimization


  • Subject: Re: Some help with Optimization
  • From: Lachlan Deck <email@hidden>
  • Date: Sun, 12 Feb 2006 21:47:50 +1100

Hi there,

On 10/02/2006, at 10:00 AM, Owen McKerrow wrote:

Objective : To get the full list of External Authors active names.

DB setup :
Person <- ->> PersonName (so a person can have many names thus allowing for name changes, while keeping the old name for historic time snap shots)

Right. i.e., inactive names are rarely needed which makes the following a regular waste of time anyway.


So in my Person class I have a function for getting the currently active name :

public PersonName activeName()
{
	int i;
	PersonName theName= null;
	for (i=0;i<personNames().count();i++) {
		PersonName temp = (PersonName)personNames().objectAtIndex(i);
		if ( temp.active().intValue() == 1 ) {
			theName = temp;
			break;
		}
	}
	return theName;
}

Is there an easier/quicker way to do this?

Don't fetch objects you'll rarely use ;-) i.e., filter out the inactive ones during the fetch...


Should I have a second to-one relationship which is for the active name?

Sounds like a much better idea. That way the 'active' class attribute goes away and you instead have a foreign key in Person. Clean. Easy.


I should note that there about 5 people in the DB which actually have more than 1 name, so in 98ish% of cases this is returns the first object.

Hence the rarity of using the extra names.

While time's relevant, I'd also suggest using primitives in for-loops (via a single object call at the beginning) instead of regular method calls per iteration. i.e.,

	for (int i = 0, count = personNames.count(); i < count; i++ ) { }

with regards,
--

Lachlan Deck

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Security Framework by David Newnann
      • From: Don Lindsay <email@hidden>
References: 
 >Some help with Optimization (From: Owen McKerrow <email@hidden>)

  • Prev by Date: technique for fixing corrupted class file?
  • Next by Date: Re: EOGenerator & Inheritance
  • Previous by thread: Re: Some help with Optimization
  • Next by thread: Security Framework by David Newnann
  • Index(es):
    • Date
    • Thread