Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ayende/ravendb
Browse files Browse the repository at this point in the history
  • Loading branch information
Fitzchak Yitzchaki committed Dec 13, 2011
2 parents fa52d87 + fd0a2d8 commit 6fc57df
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 1 deletion.
147 changes: 147 additions & 0 deletions Raven.Tests/MailingList/SkippedResults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Raven.Client.Indexes;
using Raven.Client.Linq;
using Xunit;

namespace Raven.Tests.MailingList
{
public class SkippedResults : RavenTest
{
public void Can_page_when_using_nested_property_index()
{
using (var store = NewDocumentStore())
{
using (var session = store.OpenSession())
{
for (int i = 1; i < 11; i++)
{
session.Store(CreateProvider(i));
}
session.SaveChanges();
}

new NestedPropertyIndex1().Execute(store);

// Retrieves all 10 providers in a single result set.
using (var session = store.OpenSession())
{
var result = (from p in session.Query<Provider, NestedPropertyIndex1>()
.Customize(x=>x.WaitForNonStaleResults())
where p.Zip == "97520"
select p).ToArray();
Assert.Equal(10, result.Count());
}

// Retrieves all 10 providers, 2 at a time.
using (var session = store.OpenSession())
{
const int pageSize = 2;
int pageNumber = 0;
int skippedResults = 0;
int recordsToSkip = 0;

var providers = new List<Provider>();

RavenQueryStatistics statistics;
while (true)
{
var result = (from p in session.Query<Provider, NestedPropertyIndex1>()
.Customize(x => x.WaitForNonStaleResults())
.Statistics(out statistics)
where p.Zip == "97520"
select p)
.Take(pageSize)
.Skip(recordsToSkip)
.ToList();

providers.AddRange(result);

if (result.Count < pageSize)
break;

pageNumber++;

skippedResults += statistics.SkippedResults;
recordsToSkip = pageSize*pageNumber + skippedResults;

// I found this in the Raven.Tests.MailingList.Vlad.WillOnlyGetPost2Once() method
//recordsToSkip = pageSize * pageNumber + statistics.SkippedResults;
}

Assert.Equal(10, providers.Count);
Assert.Equal(5, pageNumber);
}
}
}

private Provider CreateProvider(int i)
{
return new Provider
{
Name = "Test " + i,
Zip = "97520",
Categories = new List<Category>
{
new Category
{
EffectiveFrom = DateTime.Now,
EffectiveThrough = DateTime.Now,
Name = "a"
},
new Category
{
EffectiveFrom = DateTime.Now,
EffectiveThrough = DateTime.Now,
Name = "a"
},
new Category
{
EffectiveFrom = DateTime.Now,
EffectiveThrough = DateTime.Now,
Name = "a"
},
}
};
}


public class Category
{
public string Name { get; set; }
public DateTime EffectiveFrom { get; set; }
public DateTime EffectiveThrough { get; set; }
}


public class Provider
{
public string Name { get; set; }
public string Zip { get; set; }
public IList<Category> Categories { get; set; }
}


// Indexing nested properties
// Creates multiple index entries, one for each nested property combination
public class NestedPropertyIndex1 : AbstractIndexCreationTask<Provider>
{
public NestedPropertyIndex1()
{
Map = providers =>
from p in providers
from c in p.Categories
select new
{
p.Name,
p.Zip,
Categories_Name = c.Name,
Categories_EffectiveFrom = c.EffectiveFrom,
Categories_EffectiveThrough = c.EffectiveThrough,
};
}

}
}
}
1 change: 1 addition & 0 deletions Raven.Tests/Raven.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@
<Compile Include="MailingList\RobStats\Summary.cs" />
<Compile Include="MailingList\RobStats\TheIndex.cs" />
<Compile Include="MailingList\SetBased.cs" />
<Compile Include="MailingList\SkippedResults.cs" />
<Compile Include="MailingList\spokeypokey\spokeypokey.cs" />
<Compile Include="MailingList\spokeypokey\spokeypokey2.cs" />
<Compile Include="MailingList\spokeypokey\spokeypokey3.cs" />
Expand Down
4 changes: 3 additions & 1 deletion default.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,9 @@ task CreateNugetPackage {
$nupack = [xml](get-content $base_dir\RavenDB-Embedded.nuspec)

$nupack.package.metadata.version = "$version.$env:buildlabel"

if ($global:uploadCategory.EndsWith("-Unstable")){
$nupack.package.metadata.version += "-Unstable"
}
$writerSettings = new-object System.Xml.XmlWriterSettings
$writerSettings.OmitXmlDeclaration = $true
$writerSettings.NewLineOnAttributes = $true
Expand Down

0 comments on commit 6fc57df

Please sign in to comment.