From 1342db66743eeff1c7f72003d77f097692084d88 Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Sun, 7 Feb 2010 01:10:12 -0500 Subject: clean up scope from things removed from system.js SERVER-602 --- scripting/engine.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'scripting/engine.cpp') diff --git a/scripting/engine.cpp b/scripting/engine.cpp index c2651b3a883..515f1386e0c 100644 --- a/scripting/engine.cpp +++ b/scripting/engine.cpp @@ -164,9 +164,12 @@ namespace mongo { _loadedVersion = _lastVersion; string coll = _localDBName + ".system.js"; - + static DBClientBase * db = createDirectClient(); auto_ptr c = db->query( coll , Query() ); + + set thisTime; + while ( c->more() ){ BSONObj o = c->next(); @@ -177,10 +180,30 @@ namespace mongo { uassert( 10210 , "value has to be set" , v.type() != EOO ); setElement( n.valuestr() , v ); + + thisTime.insert( n.valuestr() ); + _storedNames.insert( n.valuestr() ); + } db->ensureIndex( coll, BSON( "_id" << 1 ) , true ); + + // --- remove things from scope that were removed + + list toremove; + + for ( set::iterator i=_storedNames.begin(); i!=_storedNames.end(); i++ ){ + string n = *i; + if ( thisTime.count( n ) == 0 ) + toremove.push_back( n ); + } + for ( list::iterator i=toremove.begin(); i!=toremove.end(); i++ ){ + string n = *i; + _storedNames.erase( n ); + execSetup( (string)"delete " + n , "clean up scope" ); + } + } ScriptingFunction Scope::createFunction( const char * code ){ -- cgit v1.2.1