• 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: caching global IDs does not work as expected (followup: ordered and filtered fault efficiency)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: caching global IDs does not work as expected (followup: ordered and filtered fault efficiency)


  • Subject: Re: caching global IDs does not work as expected (followup: ordered and filtered fault efficiency)
  • From: Chuck Hill <email@hidden>
  • Date: Sun, 15 Feb 2015 00:48:50 +0000
  • Thread-topic: caching global IDs does not work as expected (followup: ordered and filtered fault efficiency)

Hi,

This code makes no sense to me.  One of us is confused.  Given how today has been going it might be me.  Confusion below

On 2015-02-14, 1:59 AM, "OC" wrote:

P.S.

On 14. 2. 2015, at 8:34, OC <email@hidden> wrote:
I tried to cache the object's permanentGlobalID when found or added new valid one ... it still does not work well

Actually it seems I must be misunderstanding somehow the behaviour of global IDs, worth to ask for an advice what I am doing wrong.

I cache permanent GID of the found object in my relationship; the cache key is the owner's GID -- the code looks essentially like this:

===
    private static Map _lastValidPOCacheGID=[:]
    public DBPriceOffer lastValidPriceOffer { // this might happen in any EC, default or temporary
        if (_lastValidPOCacheGID[this.permanentGlobalID()]) {
            def gid=_lastValidPOCacheGID[this.permanentGlobalID()]
            def lvpo=this.editingContext().objectForGlobalID(gid) //1 finds it if exists in EC, or...

Don’t do it like this.  Use ec.faultForGlobalD().  This handles the three cases:
  • the EO is already int the EC
  • the EO snapshot exists in an EODatabase but has not been faulted into this EC (you are not handling this case with your code)
  • the object has not been fetched at all
This is not your problem, but I wanted to point that out.



            if (!lvpo) {
                lvpo=ERXEOGlobalIDUtilities.fetchObjectWithGlobalID(this.editingContext(),gid) //2 ... fetches if does not
                println "???? fetched valid PO of ${this.permanentGlobalID()}: ${gid} -> ${lvpo} IN ${this.editingContext.hashCode()}"
            } else println "???? found valid PO of ${this.permanentGlobalID()}: ${gid} -> ${lvpo} IN ${this.editingContext.hashCode()}"
            if (lvpo) return lvpo
        }
        NSArray a=orderedPriceOffers
        for (int n=a.count-1;n>=0;n--) {
            DBPriceOffer po=(DBPriceOffer)a.objectAtIndex(n)
            if (po.validOffer) {
println "???? setting found last valid PO of ${this.permanentGlobalID()}: $po -> ${po.permanentGlobalID()} IN ${po.editingContext.hashCode()}"
                _lastValidPOCacheGID[this.permanentGlobalID()]=po.permanentGlobalID()
                return po
            }
        }
        return nil
    }
    public int addPriceOffer(BigDecimal offerValue) { // this happens in a temp EC
        DBPriceOffer npo=new DBPriceOffer()
        this.editingContext.insertObject(npo)
        this.addObjectToBothSidesOfRelationshipWithKey(npo,'priceOffers')
        npo.offerValue=offerValue
        if ((npo.validOffer=_validateOffer(npo))) {
println "???? setting new valid PO of ${this.permanentGlobalID()}: $npo -> ${npo.permanentGlobalID()} IN.this ${this.editingContext.hashCode()} IN.po ${npo.editingContext.hashCode()}"
            _lastValidPOCacheGID[this.permanentGlobalID()]=npo.permanentGlobalID() // the newly added offer is valid
        ... ... ...
    }
===

Now, at beginning, it works exactly as presumed -- the valid PO is found and cached, and then found in EC; when a temp EC is created, it is fetched for the first time, then found:

=== (printout of GIDs cleaned up manually for better reading) ===
???? setting found last valid PO of [DBAuction.1000015]: <DBPriceOffer@344474980 PK:1000205 /EC:704069077> -> [DBPriceOffer.1000205] IN 704069077
???? found valid PO of [DBAuction.1000015]: [DBPriceOffer.1000205] -> <DBPriceOffer@344474980 PK:1000205 /EC:704069077> IN 704069077
???? fetched valid PO of [DBAuction.1000015]: [DBPriceOffer.1000205] -> <DBPriceOffer@890877103 PK:1000205 /EC:73728309> IN 73728309
???? found valid PO of [DBAuction.1000015]: [DBPriceOffer.1000205] -> <DBPriceOffer@890877103 PK:1000205 /EC:73728309> IN 73728309
===

When a new PO is added through addPriceOffer though, weird (to my flawed understanding) things happen: the PO is cached, is neither found in EC nor fetched, but IS found in the relationship -- what the darn?!? I would suppose it to be "found" at the line //1?!?

===
???? setting new valid PO of [DBAuction.1000015]: <DBPriceOffer@34841915 PK:null N /EC:73728309> -> [DBPriceOffer.1000206] IN.this 73728309 IN.po 73728309

Why does it say PK:null?   If a permanent GID has been assigned, should be PK not have a value?  And it is null, then null is getting cached here _lastValidPOCacheGID[this.permanentGlobalID()]=npo.permanentGlobalID()   Which I think explains why it is neither found in the EC or fetched?

Chuck



???? fetched valid PO of [DBAuction.1000015]: [DBPriceOffer.1000206] -> null IN 73728309
???? setting found last valid PO of [DBAuction.1000015]: <DBPriceOffer@34841915 PK:null N /EC:73728309> -> [DBPriceOffer.1000206] IN 73728309
===

At this moment, the new object is saved into the database.

The very same behaviour repeats later in the default EC -- again, the new PO is neither found in EC nor fetched, but IS found in the relationship -- this time, I would suppose it to be "fetched" at the line //2?!?

===
???? fetched valid PO of [DBAuction.1000015]: [DBPriceOffer.1000206] -> null IN 704069077
???? setting found last valid PO of [DBAuction.1000015]: <DBPriceOffer@1582817960 PK:1000207 /EC:704069077> -> [DBPriceOffer.1000207] IN 704069077
===

Can anyone explain the behaviour, so that I can see which of my presumptions is wrong and why?

Thanks a lot,
OC


_______________________________________________
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
 _______________________________________________
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:
    • Re: caching global IDs does not work as expected (followup: ordered and filtered fault efficiency)
      • From: OC <email@hidden>
References: 
 >ordered and filtered fault efficiency (From: OC <email@hidden>)
 >caching global IDs does not work as expected (followup: ordered and filtered fault efficiency) (From: OC <email@hidden>)

  • Prev by Date: Re: way too many SELECTs?
  • Next by Date: Re: ordered and filtered fault efficiency
  • Previous by thread: caching global IDs does not work as expected (followup: ordered and filtered fault efficiency)
  • Next by thread: Re: caching global IDs does not work as expected (followup: ordered and filtered fault efficiency)
  • Index(es):
    • Date
    • Thread