Slight optimization in pageouter (we know some totals (e.g. for posts in thread and threads in board), so there is no need in querying these from DB)

main
Inga 🏳‍🌈 12 years ago
parent de21f0ee71
commit 21e63d7d92
  1. 2
      Builder/IISMainHandler/build.txt
  2. 2
      FLocal.Common/dataobjects/Board.cs
  3. 1
      FLocal.Common/dataobjects/PMConversation.cs
  4. 1
      FLocal.Common/dataobjects/Thread.cs
  5. 10
      FLocal.IISHandler/PageOuter.cs
  6. 32
      MySQLConnector/Connection.cs
  7. 7
      Web.Core/DB/Diapasone.cs

@ -323,6 +323,7 @@ namespace FLocal.Common.dataobjects {
}
public IEnumerable<Thread> getThreads(Diapasone diapasone, SortSpec[] sortBy) {
diapasone.total = this.totalThreads;
return Thread.LoadByIds(
from stringId in Config.instance.mainConnection.LoadIdsByConditions(
Thread.TableSpec.instance,
@ -339,6 +340,7 @@ namespace FLocal.Common.dataobjects {
}
public IEnumerable<Thread> getThreads(Diapasone diapasone, bool isAscending) {
diapasone.total = this.totalThreads;
return this.getThreads(
diapasone,
new SortSpec[] {

@ -157,6 +157,7 @@ namespace FLocal.Common.dataobjects {
}
public IEnumerable<PMMessage> getMessages(Diapasone diapasone, UserContext context, bool isAscending) {
diapasone.total = this.totalMessages;
return PMMessage.LoadByIds(
from stringId in Config.instance.mainConnection.LoadIdsByConditions(
PMMessage.TableSpec.instance,

@ -237,6 +237,7 @@ namespace FLocal.Common.dataobjects {
}
public IEnumerable<Post> getPosts(Diapasone diapasone, bool isAscending) {
diapasone.total = this.totalPosts;
return Post.LoadByIds(
from stringId in Config.instance.mainConnection.LoadIdsByConditions(
Post.TableSpec.instance,

@ -74,12 +74,12 @@ namespace FLocal.IISHandler {
new XElement("unlimited", (this.count < 1).ToPlainString()),
new XElement("start", this.start),
new XElement("count", this.count),
new XElement("total", this.total),
new XElement("total", this.total.Value),
new XElement("perPage", this.perPage),
new XElement("isEmpty", (this.perPage >= this.total).ToPlainString())
new XElement("isEmpty", (this.perPage >= this.total.Value).ToPlainString())
);
if(this.count > 0) {
if(this.start + this.count < this.total) {
if(this.start + this.count < this.total.Value) {
result.Add(new XElement("next", this.start + this.count));
}
}
@ -88,7 +88,7 @@ namespace FLocal.IISHandler {
pages.Add(i*this.perPage);
}
{
long last = this.total - 1;
long last = this.total.Value - 1;
long totalFloor = last - (last % this.perPage);
for(long i=0; i<left; i++) {
pages.Add(totalFloor - i*this.perPage);
@ -102,7 +102,7 @@ namespace FLocal.IISHandler {
}
pages.Add(this.start);
result.Add(new XElement("pages",
from page in pages where (page >= 0) && (page < this.total) orderby page select new XElement("page", page)
from page in pages where (page >= 0) && (page < this.total.Value) orderby page select new XElement("page", page)
));
return result;
}

@ -138,27 +138,33 @@ namespace MySQLConnector {
command.AddParameter(kvp.Key, kvp.Value);
}
command.CommandText = logger.commandText = "SELECT COUNT(*) " + queryMain;
object rawCount;
//try {
rawCount = command.ExecuteScalar();
//} catch(Npgsql.NpgsqlException e) {
//throw new FLocalException("Error while trying to execute " + command.CommandText + ": " + e.Message);
//}
long count = (long)rawCount;
if(count < 1) {
diapasone.total = 0;
if(!diapasone.total.HasValue) {
command.CommandText = logger.commandText = "SELECT COUNT(*) " + queryMain;
object rawCount;
//try {
rawCount = command.ExecuteScalar();
//} catch(Npgsql.NpgsqlException e) {
//throw new FLocalException("Error while trying to execute " + command.CommandText + ": " + e.Message);
//}
long count = (long)rawCount;
if(count < 1) {
diapasone.total = 0;
} else {
diapasone.total = count;
}
}
if(diapasone.total.Value < 1) {
return new List<string>();
} else {
diapasone.total = count;
if(diapasone.total > 1000 && diapasone.count < 0 && !allowHugeLists) {
if(diapasone.total.Value > 1000 && diapasone.count < 0 && !allowHugeLists) {
throw new CriticalException("huge list");
}
string queryLimits = "";
if(diapasone.count >= 0) {
queryLimits = "LIMIT " + diapasone.count + " OFFSET " + diapasone.start;
}
command.CommandText = "SELECT " + table.getIdSpec().compile(this.traits) + " " + queryMain + " " + querySorts + " " + queryLimits;
command.CommandText = logger.commandText = "SELECT " + table.getIdSpec().compile(this.traits) + " " + queryMain + " " + querySorts + " " + queryLimits;
List<string> result = new List<string>();
using(DbDataReader reader = command.ExecuteReader()) {

@ -8,7 +8,11 @@ namespace Web.Core.DB {
public readonly long start;
public readonly long count;
public long total {
/// <summary>
/// Diapasone total value of null means that it has not yet been computed
/// </summary>
public long? total {
get;
set;
}
@ -16,6 +20,7 @@ namespace Web.Core.DB {
public Diapasone(long start, long count) {
this.start = start;
this.count = count;
this.total = null;
}
public static Diapasone unlimited {

Loading…
Cancel
Save