Class SessionInitialiser.

Inherits EventHandler

The SessionInitialiser class performs the database queries needed to initialise or update Session objects.

When it's created, it tries to see whether the database work can be skipped. If not, it does all the necessary database queries and updates, and finally informs the Session objects of new and modified Message objects.

SessionInitialiser::SessionInitialiser( Mailbox * mailbox, Transaction * t )

Constructs an SessionInitialiser for mailbox. If t is non-null, then thr initialiser will use a subtransaction of t for its work.

void SessionInitialiser::addToSessions( uint uid, int64 ms )

Adds uid with modseq ms to each session to be announced as changed or new.

void SessionInitialiser::emitUpdates()

Persuades each Session to emit its responses.

void SessionInitialiser::findMailboxChanges()

Issues a query to find new and changed messages in the mailbox, and one to find newly expunged messages.

void SessionInitialiser::findRecent()

Fetches the "\recent" data from the database and sends an update to the database if we have to change it. Note that this doesn't release our lock.

void SessionInitialiser::findSessions()

Finds all sessions that may be updated by this initialiser. Doesn't lock anything.

void SessionInitialiser::findUidnext()

It may be that Mailbox::uidnext() is a little behind the times. If we retrieve the values from the database anyway, this function updates the Mailbox.

void SessionInitialiser::findViewChanges()

Constructs a big complex query to find out what a view's contents should be like, which writeViewChanges() can use to update the view_messages table and the Sessions. Takes care to make the query as simple as possible, so it only looks at modseq if necessary.

The generated query is big, complex and invariant. Perhaps we should try to make a PreparedStatement. Not sure how. There's nowhere natural to put it.

void SessionInitialiser::grabLock()

Grabs enough locks on the database that we can update what we need to update: Only one session must get the "\recent" flag, and if we change view contents, noone else must do so at the same time.

void SessionInitialiser::recordExpunges()

Finds any expunges stored in the db, but new to us, and records those in all the sessions.

void SessionInitialiser::recordMailboxChanges()

Parses the results of the Query generated by findMailboxChanges() and updates each Session.

void SessionInitialiser::releaseLock()

Commits the transaction, releasing the locks we've held, and updates the state. After this we're done.

void SessionInitialiser::submit( Query * q )

This private helper submits q via our Transaction if we're using one, directly if not.

void SessionInitialiser::writeViewChanges()

Processes the query results from the Query generated by findViewChanges(), adds to and/or removes from the view_messages table and the in-RAM Session object as a result, and updates the view so the next SessionInitialiser will not have to consider the same messages.

This web page based on source code belonging to The Archiveopteryx Developers. All rights reserved.