Hi Henrik,
> I think I get the ObjFun part in:
>
> (de dbMap ("ObjFun" "TreeFun")
> (default "ObjFun" quote "TreeFun" quote)
> (finally (mark 0)
> (_dbMap *DB)
> (dbMapT *DB) ) )
>
> But what about the TreeFun?
If you pass a 'TreeFun' argument, it should be a function that accepts a
tree. This is useful if you want to do something with the trees
explicitly, as a whole (like checking them). Probably not what we need
here.
'dbMap' will iterate all trees, and apply 'ObjFun' to all objects found
in them.
> Pretend I want to loop through all +FeedTags:
> (class +FeedTag +Entity) #
> (rel user (+Ref +Link) NIL (+User)) #
> (rel tag (+Aux +Ref +Link) (user) NIL (+Tag)) #
> (rel feed (+Aux +Ref +Link) (user) NIL (+Feed)) #
>
> And remove all of them where the tag or feed object is missing, what
> would the dbMap call look like?
Note that this is something different. To iterate through all objects of
a given class, you should do:
(for (Obj (seq (db: +Cls)) Obj (seq Obj))
(when (isa '+Cls Obj)
(doSomethingWith Ob)
...
'dbMap', on the other hand, does not necessarily iterate through all
objects of a given class (or DB file), but through all objects it finds
by traversing the index trees. In case of a corrupted database, this
might give different results.
To iterate through all +FeedTag objects, you could do
(for (This (seq (db: +FeedTag)) This (seq This))
(and
(isa 'FeedTag This)
(nand (ext? (: tag)) (ext? (: feed)))
(lose!> This) ) )
This would do something you asked. But again note that this may not work
on a corrupted DB, as the losing itself will also try to modify
(probably corrupted) index trees etc.
BUT: This is not the problem we found in your DB. In the error message
which you posted in your original mail, we saw that it found a dead
object in a _tree_node_, not in a link like 'tag' or 'feed' from one
object to another. And, as I can see from the error message, that dead
object (it was '{I-4FSO}') is not an entity (like a '+FeedTag'), but the
CAR of the Node which points to another node in that Btree.
To while you could do something with all +FeedTag objects referred to
from index trees,
(dbMap '((Obj) (and (ext? Obj) (isa '+FeedTag Obj) (writeObjectToFile Obj))))
or (simpler and more efficiently), directly iterate a given FeedTag tree,
(iter (tree 'user '+FeedTag)
'((This)
(when (ext? This)
...
both 'dbMap' and 'iter' may be problematic here, as they will probably
crash when they try to traverse the broken tree. So I would recommend to
stay with the above solution using 'seq' in a 'for' loop directly on the
database file.
Cheers,
- Alex
--
UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe