# Slow response when "event" is triggered

**URL:** <https://forum.inductiveautomation.com/t/slow-response-when-event-is-triggered/69501>\
**Category:** General Discussion\
**Tags:** scripting\
**Created:** [February 6, 2023, 8:02pm UTC](https://forum.inductiveautomation.com/t/slow-response-when-event-is-triggered/69501 "2023-02-06T20:02:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Blaschuk](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Ben\_Blaschuk](https://forum.inductiveautomation.com/u/Ben_Blaschuk)\
**Post date:** [February 6, 2023, 8:02pm UTC](https://forum.inductiveautomation.com/t/slow-response-when-event-is-triggered/69501/1 "2023-02-06T20:02:45Z")

</div>

i have a script on a calendar that changes a few custom properties when the date is changed. One of these custom properties is using the system.tag.queryTagHistroy to take an average of the amount of "on time" there is over a given work shift (8hr/9hr depending) when i change the date, there is a couple of second delay before the data changes. This looks clunky when going through and checking out each day. Is there a way to make this delay go away? do i need to move out of the script and use jsut a table in general? here is a copy of the specific script.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/0/c0810200591c2b1111684c449a5ce973ccaea4a1.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 6, 2023, 8:08pm UTC](https://forum.inductiveautomation.com/t/slow-response-when-event-is-triggered/69501/2 "2023-02-06T20:08:32Z")

</div>

Where did you put this script?

If this is a Vision propertyChange script, then you don't have any check for which property changed, and that will flood your UI with extraneous executions.

{ Always start with `if event.propertyName == 'somePropName':` and indent the actual code under that `if`. }

---

<div class="post-metadata">

**Author:** ![Ben\_Blaschuk](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Ben\_Blaschuk](https://forum.inductiveautomation.com/u/Ben_Blaschuk)\
**Post date:** [February 6, 2023, 8:15pm UTC](https://forum.inductiveautomation.com/t/slow-response-when-event-is-triggered/69501/3 "2023-02-06T20:15:56Z")

</div>

It is in the calendar itself. it's how I get the other custom properties their values. but none of them are 8 tags large just 1. the changing of the date is the event.

when the date changes, then the "event" is triggered and it runs. Also, I don't understand how to use your suggestion. my understanding of what I need to do is likely less than a 5th grader at this point.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 6, 2023, 8:32pm UTC](https://forum.inductiveautomation.com/t/slow-response-when-event-is-triggered/69501/4 "2023-02-06T20:32:50Z")

</div>

> [@Ben\_Blaschuk](#):
>
> when the date changes, then the "event" is triggered and it runs.

Yes, your code runs on date changes. But other things can change on that component, and those will run your code, too. Indent your code. Add the `if` statement above it. (With the correct property name. Shown in a tooltip if you hover over the prop in the property editor.)

---

<div class="post-metadata">

**Author:** ![Ben\_Blaschuk](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Ben\_Blaschuk](https://forum.inductiveautomation.com/u/Ben_Blaschuk)\
**Post date:** [February 6, 2023, 8:33pm UTC](https://forum.inductiveautomation.com/t/slow-response-when-event-is-triggered/69501/5 "2023-02-06T20:33:08Z")

</div>

ok.. I looked up how to do this and it went event slower. I commented out everything one by one and its at the same place. When the above start to gather it's data, it slows down. Is it the number of tags it's trying to look at? could it be that i have the dataset row = to 1 instead of a super large table? is it the average im trying to calculate? maybe?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 6, 2023, 8:34pm UTC](https://forum.inductiveautomation.com/t/slow-response-when-event-is-triggered/69501/6 "2023-02-06T20:34:49Z")

</div>

Ok. Then it probably means you haven't optimized your DB. An index on the historian table's `t_stamp` column should be present.

Or your DB is on a wimpy system that just can't deliver/process a shift's worth of data quickly.

---

<div class="post-metadata">

**Author:** ![Ben\_Blaschuk](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Ben\_Blaschuk](https://forum.inductiveautomation.com/u/Ben_Blaschuk)\
**Post date:** [February 6, 2023, 8:36pm UTC](https://forum.inductiveautomation.com/t/slow-response-when-event-is-triggered/69501/7 "2023-02-06T20:36:55Z")

</div>

does this look right then? And it could be that what we are running is not "strong" enough. Something I cannot change I'm afraid..

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/1/91234abf4224a07bfdb7015c852bf351a785f61f.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 6, 2023, 9:26pm UTC](https://forum.inductiveautomation.com/t/slow-response-when-event-is-triggered/69501/8 "2023-02-06T21:26:26Z")

</div>

> [@Ben\_Blaschuk](#):
>
> does this look right then?

That provides no information about the DB's indices. You would look at the DB through its workbench or some other administration tool. (I recommend DataGrip, fwiw.)

---

<div class="post-metadata">

**Author:** ![Ben\_Blaschuk](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Ben\_Blaschuk](https://forum.inductiveautomation.com/u/Ben_Blaschuk)\
**Post date:** [February 6, 2023, 9:38pm UTC](https://forum.inductiveautomation.com/t/slow-response-when-event-is-triggered/69501/9 "2023-02-06T21:38:08Z")

</div>

I put it in a different location in the script and it helped a little. thanks 🙂

---

<div class="post-metadata">

**Author:** ![Steve\_Laubach](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steve_laubach/32/60900_2.png) [@Steve\_Laubach](https://forum.inductiveautomation.com/u/Steve_Laubach)\
**Post date:** [February 13, 2023, 9:28pm UTC](https://forum.inductiveautomation.com/t/slow-response-when-event-is-triggered/69501/10 "2023-02-13T21:28:50Z")

</div>

I deduce that it tells you that the indices are not present. 🙂
