Duplicate events in tables

Hello there.
I’m trying to get events from the contract but after going through the documentation and implementing

Moralis.Cloud.beforeConsume(eventTableName, (event) => {
  return event && event.confirmed;
});

Moralis.Cloud.afterSave("xxx", async function(request) {
  const confirmed = request.object.get("confirmed");
  if (confirmed) {
    // do something
  } else {
    // handle unconfirmed case
  }
});

I still see that I get duplicate events saved in the database sometimes event triple saved…
I don’t understand why it’s saving same event multiple times when I want only one event

Hi @Mugen

Please share your server subdomain :raised_hands:

https://xagwzevmpg8p.usemoralis.com:2053/server
@Yomoo

How can I prevent saving object to the table if a key already exists in the table (transaction_hash)

You could try to use beforeSave hook, but I don’t know why you have those duplicates in the first place
Or you can run a job that removes the duplicates

Its because of internal contracts transactions. If contract does some other internal transactions inside of one transaction it can register those and in turn im getting sometimes multiple records of the same hash transaction