summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-02-07 01:10:12 -0500
committerEliot Horowitz <eliot@10gen.com>2010-02-07 01:10:12 -0500
commit1342db66743eeff1c7f72003d77f097692084d88 (patch)
tree12a4e3a929aae2b5443157fa911a2cd1711d971d /scripting
parent656cd3a9f46625f4b3223030e8ffe5f51233ca3d (diff)
downloadmongo-1342db66743eeff1c7f72003d77f097692084d88.tar.gz
clean up scope from things removed from system.js SERVER-602
Diffstat (limited to 'scripting')
-rw-r--r--scripting/engine.cpp25
-rw-r--r--scripting/engine.h1
2 files changed, 25 insertions, 1 deletions
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<DBClientCursor> c = db->query( coll , Query() );
+
+ set<string> 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<string> toremove;
+
+ for ( set<string>::iterator i=_storedNames.begin(); i!=_storedNames.end(); i++ ){
+ string n = *i;
+ if ( thisTime.count( n ) == 0 )
+ toremove.push_back( n );
+ }
+ for ( list<string>::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 ){
diff --git a/scripting/engine.h b/scripting/engine.h
index 137bc46f5e2..371c3ffb1da 100644
--- a/scripting/engine.h
+++ b/scripting/engine.h
@@ -111,6 +111,7 @@ namespace mongo {
string _localDBName;
long long _loadedVersion;
+ set<string> _storedNames;
static long long _lastVersion;
map<string,ScriptingFunction> _cachedFunctions;