Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    updateCaches and duplicated records

    SmartClient Version: v9.0p_2013-11-15/PowerEdition Development Only

    Using the RealtimeMessaging, I noticed that the DataSource.updateCaches method, with an add operation, will duplicate existing records.
    I just verified this using the sample #fetchOperationFS, and executing the code:
    Code:
    supplyItem.updateCaches({data: [{itemName: "Adding Machine Roll 57x57mm Standard",
    category: "Adding Machine/calculator Roll",
    itemID: 1,
    unitCost: 0.41,
    SKU: "45300",
    inStock: true,
    units: "Roll"}], startRow: 0, endRow: 1, totalRows: 1, status: 0}, {operationType: 'add'})
    I thought that it wouldn't duplicate the record, based on the primaryKey.
    Is it intended behaviour?
    The problem arises when I make a grid.addData, and that grid has subscribed to receive messaging from the 'add' channel.
    Have I to check for duplicated records in the 'subscribe' callback?

    #2
    Can't you change 'add' to 'update', like this?

    Code:
    isc.DataSource.get("nameOfDS").updateCaches({ operationType: "update", data: [{itemName: "Adding Machine Roll 57x57mm Standard",
    category: "Adding Machine/calculator Roll",
    itemID: 1,
    unitCost: 0.41,
    SKU: "45300",
    inStock: true,
    units: "Roll"}] });

    Comment


      #3
      I think not. I must specify that I'm using realtime messaging.
      My use case involves a grid where a user adds a record, and the same grid has subscribed to receive new records on a 'add' channel.
      So the grids duplicates every added record, because of the 'pushed' add.

      Comment


        #4
        If there's already a record with that primaryKey, it would seem that you've either got a corrupt database with two records with the same PK, or you should have also propagated a "remove" operation that allows an "add" with the same PK to become valid.

        Comment


          #5
          Obviously I'm not explaining well my use case.

          I have got a grid, databound to a dataSource 'ORDINE'

          clients subscribe to a 'addOrdine' channel, so that the former grid shows new records added (via a callback which calls ORDINE.updateCaches())

          if I do
          grid.addData(newRecord, "isc.Messaging.send('jms/addOrdine', data)")

          the record is inserted on the database, and will show correctly on the *others* clients showing that same grid.

          But on the client where the addData has been executed, the record will show duplicated in the grid (one for the addData, and another for the updateCaches).

          Comment


            #6
            Ah, that makes sense. Yes, ResultSet will not try to determine if an record in an "add" updateCache() call actually has a unique key before updating the cache. That would cause a performance hit.

            You should avoid sending that update to the client that actually made the change, or come up with a way of ignoring it, for instance by introducing some kind of clientId so a client can ignore its own updates.

            Comment

            Working...
            X