[Cosmo-dev] Re: [commits-cosmo] (br) [2474] making save work.

Bobby Rullo br at osafoundation.org
Tue Sep 12 21:00:36 PDT 2006


Brian,

That IS what I'm doing - but I'm also making sure that that name  
hasn't been taken by some stroke of bad luck.

The only extra cost incurred in 99.9999% of instances is the extra  
check to make sure that another item doesn't happen to be using that  
name.

I could easily just not check, and assume that never happens, which  
would almost always be ok.

Bobby

On Sep 12, 2006, at 6:05 PM, Brian Moseley wrote:

> On 9/12/06, svncheckin at osafoundation.org  
> <svncheckin at osafoundation.org> wrote:
>
>> + private String findAvailableName(String calendarPath, VEvent  
>> vevent)
>> throws RPCException{
>> + char[] chars = {'0', '1', '2', '3', '4', '5', '6', '6', '8', '9'};
>> + StringBuffer baseName = new StringBuffer(vevent.getUid().getValue 
>> ())
>> + .append(".ics");
>> + int index = baseName.length() - 4;
>> + int count = 0;
>> + boolean foundAGoodName = false;
>> +
>> + while (!foundAGoodName && count < 10) {
>> + if (count == 1){
>> + baseName.insert(index, '0');
>> + } else if (count > 1){
>> + baseName.setCharAt(index, chars[count]);
>> + }
>> + if (contentService.findItemByPath(getAbsolutePath(calendarPath
>> + + "/" + baseName.toString())) == null) {
>> + foundAGoodName = true;
>> + }
>> + count++;
>> + }
>> +
>> + if (!foundAGoodName){
>> + throw new RPCException("Could not find a suitable name for  
>> event!");
>> + }
>> +
>> + return baseName.toString();
>> + }
>
> not a big fan of this method. ContentService.findItemByPath is
> expensive, because we have to resolve the path by walking the tree of
> items in the database.
>
> you're generating an icalendar uid for the event somewhere, right?
> that's guaranteed to be unique within the calendar collection (and
> depending on how you generate the uid, unique in the universe). why
> not make the name of the item <uid>.ics? this mirrors what chandler
> and likely many other clients do.
> _______________________________________________
> cosmo-dev mailing list
> cosmo-dev at lists.osafoundation.org
> http://lists.osafoundation.org/mailman/listinfo/cosmo-dev



More information about the cosmo-dev mailing list