Ampere hour counter over battery life

I am new to InfluxQL and have the following problem:
I have a sensor that measures the current and voltage of a battery and writes these values to the database at 100ms intervals.
I want to build an Ah counter that counts the total amp hours over the lifetime of the battery.
I have already achieved the following:

    from(bucket: "Sensor")
        |> range(start: -365d)
        |> filter(fn: (r) => r["_measurement"] == "Batterie_Sensor")
        |> filter(fn: (r) => r["_field"] == "BatteryCurrent")
        |> integral(unit: 100ms)
        |> duplicate(column: "_stop", as: "_time")
        |> map(
            fn: (r) =>
                    _time: r._time,
                    _value: r._value / 36000.0,
                        // Umrechnung von Ampere in Ampere-Stunden (Ah)
        |> set(key: "_measurement", value: "Ah_Counter")
        |> to(
            bucket: "canpi",
            org: "test",
            tagColumns: ["_time"],
            fieldFn: (r) => ({_value: r._value}),

this works so far, but in my opinion it is very inefficient because the integral is always formed over all available data.

Is it possible to create a task that runs every second, integrates the Ah over this period and then adds it to the last value of the counter?
The result should be written to a new field in the database.

According to the formula: Ah_Counter=Ah_Counter + integral(delta_t,delta_current)