         syncstring_db = new StringsDB(database)
         cb?()
 
+# queries the syncstring_acls table for all syncstring id’s, one by one goes through and
+# loads them and combines all the patches into a single patch.  As it goes, it also
+# record the total length of the resulting syncstring.
+exports.compact_all_syncstrings = (cb) ->   # cb(err, lengths); where lengths[string_id] = length of that string
 
 exports.get_syncstring_db = () ->
     return syncstring_db

        if err
            opts.cb(err)
        else
            S.new_browser_client opts.session_id, opts.push_to_client, (err, client) ->
                if err
                    opts.cb(err)
                else
                    opts.cb(undefined, client)

# The hub has to call this on startup in order for syncstring to work.
syncstring_db = undefined

        @clients = {}
        @head = ''

    new_browser_client: (opts) =>
        opts = defaults opts,
            session_id     : required
            push_to_client : required
            cb             : required
        client = new SyncStringBrowser(@, opts.session_id, opts.push_to_client)
        client.id = opts.session_id
        @clients[opts.session_id] = client
        opts.cb(undefined, client)

    new_in_memory_client: (opts) =>
        opts = defaults opts,
            session_id    : required
            cb            : required
        # Used so that the hub itself (the process where this code is running)
        # can modify this SynchronizedString, rather than just remote clients.
        client = new diffsync.DiffSync(doc:@head)
        client.id = opts.session_id
        client.sync = (cb) =>
            client.shadow    = client.live
            client.last_sync = client.live
            client.emit('sync')
            @sync()
            cb?()
        @clients[opts.session_id] = client
        opts.cb(undefined, client)

    new_database_client: (opts) =>
        opts = defaults opts,
            session_id    : required
            squash_thresh : DB_PATCH_SQUASH_THRESH
            cb            : required
        # Used for synchronizing/persisting the string using the database, so
        # it gets sync'd across all hubs (across data centers).
        syncstring_db.get_string
            string_id     : @string_id
            squash_thresh : opts.squash_thresh
            cb            : (err, client) =>
                if err
                    opts.cb(err)
                else
                    @clients[opts.session_id] = client
                    opts.cb(undefined, client)

    sync: (cb) =>
        @_call_with_lock(@_sync, cb)
