Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multitenant indexes in RavenDB in asp.net MVC

In a multitenant RavenDB application (one database per tenant, and one 'overview' database with general tenant data), what would be the index creation strategy? (asp.net mvc)

In a simple (not multitenant) application, you can create the indexes in global.asax.

  • Theoretically you could query for each tenant, and create the indexes for every tenant, in global.asax. But I guess that would be a huge performace hit when the amount of tenants go up...
  • Creating the indexes on tenant creation is not possible, as existing tenants should be able to get new indexes on updates.

So what would be the best practice as for how and when to create these indexes?

like image 399
Tom Deleu Avatar asked Jan 06 '12 08:01

Tom Deleu


1 Answers

You can use this method on application startup, no worries about perf.

public static void CreateIndexesForDatabases(Assembly assemblyToScanForIndexingTasks, IDocumentStore documentStore, string[] databases)
{
    var catalog = new CompositionContainer(new AssemblyCatalog(assemblyToScanForIndexingTasks));
    foreach (var database in databases)
    {
        IndexCreation.CreateIndexes(catalog, documentStore.DatabaseCommands.ForDatabase(database), documentStore.Conventions);
    }
}

just don't forget to include Raven.Client.Extensions

like image 126
Daniel Lang Avatar answered Oct 30 '22 16:10

Daniel Lang