I’ve been meaning to write little blog posts about some of the innovations of the last five years, to catch up the Frontier-kernel mail list and other interested Frontier coders.

This one is a small bit of code that made a huge difference in writing web apps with Frontier.

visitReverseChronologic (adrcal, adrvisit, flDayLevel=false)

adrcal is the address of a calendar-structured object database table.

adrvisit is the address or a callback that’s called for each item visited. If the callback returns false the traversal stops. If true, it continues.

if flDayLevel is true, the callback is called once for each day, otherwise it’s called once for each item in each day.

Why this is so important.

Before having this ability, for data that I needed to visit in reverse-chronologic order, I’d put it in a flat table and loop over the items from last to first using the downto option in a Frontier loop. This was fine as long as the tables were small, but they’d inevitably get large, usually long after I wrote the code, often when I wasn’t even watching. The server would just get slow, and slower, and even slower.

Further, the hit would come when loading the big table, not so much when visiting. Just looking at one item forced every item to be loaded.

Now, with the approach made possible by visitReverseChronologic, the really old items never get loaded. And you start a fresh table every day, so unless you’re getting 100K new entries every day, you’re probably going to be okay.

I use this heavily in the River2 aggregator. I have one main calendar structure for all the news items, and a calendar structure of pointers for each feed. It has all the performance characteristics I want.

Like a lot of the innovations of the last few years, this took about an hour or two to write, and a couple of days to perfect. The hard part wasn’t the writing. It just took time to realize that this is what was needed.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: