SofaDoc

SofaDoc Map Usage

inc/db.php

Contains the swDB class which is responsible for the indexes
There is one global instance $db that handles the indexes.
It does not handle writing of new records. This is done in inc/record.php.
It observes changes and updates indexes based on need.
Note that to look up a record by URL, the indexes are not used.
The hashes of the filenames in the current folder are the index for that.
General architecture
Document oriented database inspired from couchdb but using semantic metawiki syntax
The database has no tables and no predefined fields.
Fields are declared inline using the semantic mediawiki syntax [[fieldname::value]].
Fieldnames cannot start with an underscore.
Multiple occurences of the same field are allowed.
The records are self-contained.
The records are stored as revisioned files adding a header with the reserved fields.
_id automatically generated integer
_revision automatically generated integer
_name the wiki name, can change over time
_timestamp sever time
_status ok, request, protected, deleted
The filename is the revision.tx. The written files are never changed afterwards.
Every change creates a new revision,.
On insertion of a new revision, the database writes some indexes.
These indexes are for performance only, they can be rebuild whenever needed from scratch.
Note: PHP needs write access to the site folders and subfolders.

Classes

swDB extends swPersistance

Holds the database indexes
$indexedbitmap revisions that have been indexed in urldb
$currentbitmap revisions that are the last version and have the status ok or protected (these are the only filters should check)
$deletedbitmap revisions with status deleted
$protectedbitmap revisions with status protected
$bloombitmap revisions with have been indexed by the bloom filter
$urldb database of url names and revision
All these objects are persistent in site/indexes/.
The bitmaps are serialized objects.
The urldb is a sqlite3 db.

Methods

init($force=false)
close()
__destruct()
getLastRevisionFolderItem($force=false)
rebuildIndexes($lastindex=)
updateIndexes($rev,$topdown=false)
rebuildBitmaps()

Properties

$indexedbitmap
$currentbitmap
$deletedbitmap
$protectedbitmap
$bloombitmap
$fulltextbitmap
$urldb
$touched
$salt
$hasindex
$lastrevision
$persistance2
$inited
$currentupdaterev
$pathbase

Functions

swGetLastRevision()

Returns the number of the last revision.
Made a global function to replace global $db declaration in code blocks.

swGetCurrentRevisionFromName($name)

Returns current revision for a name
@param name

swGetLastRevisionFromName($name)

Returns most recent revision for a name
@param name

swGetAllRevisionsFromName($name)

Returns all revisions for a name to build a history
@param name

swGetPath($revision,$current=false)

Returns the file path for a revision
@param revision
@param current

Used elements

Classes

swBitmap, swRecord

Functions

echotime, swDbaExists, swDbaFetch, swDbaFirstKey, swDbaNextKey, swDbaOpen, swDbaReplace, swDbaSync, swIndexBloom, swInitRamdisk, swNameURL

Globals

$db, $rebuildstarttime, $swAllRevisionsCache, $swCurrentRevisionCache, $swCurrentRevsisionCache, $swError, $swLastRevisionCache, $swOvertime, $swRamdiskPath, $swRoot

Variables

$bitmaperror, $current, $error, $fields, $file, $firststatus, $force, $lastindex, $lastwrite, $line, $maxf, $name, $nowtime, $oldrev, $oldstatus, $path, $revision, $revs, $source, $status, $swIndexError, $swMemoryLimit, $urldbpath

Short variables: $c, $dir, $dur, $f, $i, $key, $m2, $r, $rev, $s, $url

Features

array, error, file, math, php, string, time, variable