Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8184 (new enhancement)

Opened 2 years ago

Last modified 1 year ago

[PATCH] maxFrequency for Ajax.PeriodicalUpdater's decay

Reported by: mamulsow Assigned to: sam
Priority: normal Milestone: 2.x
Component: Prototype Version: edge
Severity: normal Keywords: prototype ajax periodicalUpdater
Cc: zerodeux

Description

A maximum decay and/or maximum frequency (period) for Ajax.PeriodicalUpdater would be very useful. Maybe something like this in the updateComplete part of Ajax.PeriodicalUpdater:

this.timer = setTimeout(this.onTimerEvent.bind(this),
  ((this.decay < this.maxDecay) ? (this.decay * this.frequency * 1000) : (this.maxDecay * this.frequency * 1000)));

Attachments

add_periodicalupdater_max_frequency_for_decay.diff (1.0 kB) - added by kampers on 08/21/07 02:35:36.
add_periodicalupdater_max_frequency_for_decay.2.diff (0.9 kB) - added by kampers on 08/21/07 16:40:43.
updated for trunk as of [7353] as promised
periodical-updater-frequency-min.patch (0.8 kB) - added by zerodeux on 10/19/07 10:49:00.

Change History

08/21/07 02:35:02 changed by kampers

  • keywords set to prototype ajax periodicalUpdater.
  • priority changed from low to normal.
  • summary changed from maxDecay for Ajax.PeriodicalUpdater to [PATCH] maxFrequency for Ajax.PeriodicalUpdater's decay.

Here's a patch for this. I seem to want this in every single project where I use PeriodicalUpdater.

I decided to go with maxFrequency because it's more idiomatic for the user ("wait no more than maxFrequency seconds between requests" vs. "wait no more than frequency divided by maxDecay seconds between requests"). The most efficient implementation of this requires some refactoring; I changed PeriodicalUpdater so that it keeps track of the accumulated decay by changing this.frequency instead of this.decay.

This patch also rolls in the change from #9321, since decaying is broken without it. If you commit that first, I'll be happy to update the diff for this patch against the fixed trunk. For now, it's patched against the broken trunk. So if you commit this first, forget #9321.

08/21/07 02:35:36 changed by kampers

  • attachment add_periodicalupdater_max_frequency_for_decay.diff added.

08/21/07 16:40:43 changed by kampers

  • attachment add_periodicalupdater_max_frequency_for_decay.2.diff added.

updated for trunk as of [7353] as promised

10/19/07 10:48:13 changed by zerodeux

  • cc set to zerodeux.

The "frequency" term is really misleading as it really is a period (in seconds), not a frequenci (in Hz). The result which we want to achieve can be termed as either a "minimum frequency" or "a maximum period".

I have chosen the option "frequencyMin" for this purpose. It's really a "periodMax" but at least it's coherent with the whole inversion thing.

Here is a complete and similar patch against trunk src (periodical-updater-frequency-min.patch), it is trivila and vitally useful for many applications. Think about a chat, where you can use decay to reduce load and give faster updates to posters. But you need to guarantee a minimum refresh rate.

Please consider for next release, it's a backward compatible patch.

10/19/07 10:49:00 changed by zerodeux

  • attachment periodical-updater-frequency-min.patch added.