| The following code derived from mmalc's article on Stepwise is what I have been using to store "favourites" to the database. I show the items that have been marked as favourites when the page loads. When I submit, the code loops through every artifact in the database (some 20,000) and is dog slow. The inefficiency didn't show up until I connected to the production database. Does anyone have any suggestions for how I might make this code more efficient? Thanks, David /** @TypeInfo Artifact */ public NSArray favourites() { if (favourites == null) { favourites = favAppPermission.favouriteArtifacts(); //get favourites from the database } return favourites; } /** @TypeInfo Artifact */ public NSMutableArray selectionList() { if (selectionList == null) { selectionList = new NSMutableArray(favourites.mutableClone()); // set the UI the same as the contents of the database } return selectionList; } public boolean artifactChecked() { return selectionList.containsObject(anArtifact); // is the item checked in the UI? } public void setArtifactChecked(boolean newArtifactChecked) { if ( newArtifactChecked) { if (!selectionList.containsObject(anArtifact)) { selectionList.addObject(anArtifact); } } else if (selectionList.containsObject(anArtifact)) { selectionList.removeObject(anArtifact); mostRecentRemoval.addObject(anArtifact); } } public WOComponent submit() { Session session = (Session)session(); EOEditingContext ec = session.defaultEditingContext(); int y = 0; while (mostRecentRemoval.count() != y) { anArtifact = (Artifact)mostRecentRemoval.objectAtIndex(y); favAppPermission.removeObjectFromBothSidesOfRelationshipWithKey(anArtifact, "favouriteArtifacts"); ++y; } int z = 0; while (selectionList.count() != z) { anArtifact = (Artifact)selectionList.objectAtIndex(z); favAppPermission.addObjectToBothSidesOfRelationshipWithKey(anArtifact, "favouriteArtifacts"); ++z; } ec.saveChanges(); return null; } CheckBox1: WOCheckBox { checked = artifactChecked; } |
_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]
