123123
This commit is contained in:
@@ -20,7 +20,8 @@ namespace ZelWiki.Repository
|
||||
return ManagedDataStorage.Pages.QuerySingleOrDefault<Page>("GetPageRevisionInfoById.sql", param);
|
||||
}
|
||||
|
||||
public static ProcessingInstructionCollection GetPageProcessingInstructionsByPageId(int pageId, bool allowCache = true)
|
||||
public static ProcessingInstructionCollection GetPageProcessingInstructionsByPageId(int pageId,
|
||||
bool allowCache = true)
|
||||
{
|
||||
if (allowCache)
|
||||
{
|
||||
@@ -41,7 +42,8 @@ namespace ZelWiki.Repository
|
||||
|
||||
return new ProcessingInstructionCollection()
|
||||
{
|
||||
Collection = ManagedDataStorage.Pages.Query<ProcessingInstruction>("GetPageProcessingInstructionsByPageId.sql", param).ToList()
|
||||
Collection = ManagedDataStorage.Pages
|
||||
.Query<ProcessingInstruction>("GetPageProcessingInstructionsByPageId.sql", param).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -68,7 +70,8 @@ namespace ZelWiki.Repository
|
||||
}
|
||||
|
||||
public static List<PageRevision> GetPageRevisionsInfoByNavigationPaged(
|
||||
string navigation, int pageNumber, string? orderBy = null, string? orderByDirection = null, int? pageSize = null)
|
||||
string navigation, int pageNumber, string? orderBy = null, string? orderByDirection = null,
|
||||
int? pageSize = null)
|
||||
{
|
||||
pageSize ??= ConfigurationRepository.Get<int>("Customization", "Pagination Size");
|
||||
|
||||
@@ -83,7 +86,8 @@ namespace ZelWiki.Repository
|
||||
{
|
||||
using var users_db = o.Attach("users.db", "users_db");
|
||||
|
||||
var query = RepositoryHelper.TransposeOrderby("GetPageRevisionsInfoByNavigationPaged.sql", orderBy, orderByDirection);
|
||||
var query = RepositoryHelper.TransposeOrderby("GetPageRevisionsInfoByNavigationPaged.sql", orderBy,
|
||||
orderByDirection);
|
||||
return o.Query<PageRevision>(query, param).ToList();
|
||||
});
|
||||
}
|
||||
@@ -96,7 +100,8 @@ namespace ZelWiki.Repository
|
||||
TopCount = topCount
|
||||
};
|
||||
|
||||
return ManagedDataStorage.Pages.Query<PageRevision>("GetTopRecentlyModifiedPagesInfoByUserId.sql", param).ToList();
|
||||
return ManagedDataStorage.Pages.Query<PageRevision>("GetTopRecentlyModifiedPagesInfoByUserId.sql", param)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public static string? GetPageNavigationByPageId(int pageId)
|
||||
@@ -149,12 +154,13 @@ namespace ZelWiki.Repository
|
||||
});
|
||||
}
|
||||
|
||||
private static List<PageSearchToken> GetMeteredPageSearchTokens(List<string> searchTerms, bool allowFuzzyMatching, bool allowCache = true)
|
||||
private static List<PageSearchToken> GetMeteredPageSearchTokens(List<string> searchTerms,
|
||||
bool allowFuzzyMatching, bool allowCache = true)
|
||||
{
|
||||
if (allowCache)
|
||||
{
|
||||
//This caching is really just used for paging - so we don't have to do a token search for every click of next/previous.
|
||||
var cacheKey = WikiCacheKeyFunction.Build(WikiCache.Category.Search, [string.Join(',', searchTerms), allowFuzzyMatching]);
|
||||
var cacheKey = WikiCacheKeyFunction.Build(WikiCache.Category.Search,
|
||||
[string.Join(',', searchTerms), allowFuzzyMatching]);
|
||||
if (!WikiCache.TryGet<List<PageSearchToken>>(cacheKey, out var result))
|
||||
{
|
||||
result = GetMeteredPageSearchTokens(searchTerms, allowFuzzyMatching, false);
|
||||
@@ -167,11 +173,11 @@ namespace ZelWiki.Repository
|
||||
var minimumMatchScore = ConfigurationRepository.Get<float>("Search", "Minimum Match Score");
|
||||
|
||||
var searchTokens = (from o in searchTerms
|
||||
select new PageToken
|
||||
{
|
||||
Token = o,
|
||||
DoubleMetaphone = o.ToDoubleMetaphone()
|
||||
}).ToList();
|
||||
select new PageToken
|
||||
{
|
||||
Token = o,
|
||||
DoubleMetaphone = o.ToDoubleMetaphone()
|
||||
}).ToList();
|
||||
|
||||
if (allowFuzzyMatching == true)
|
||||
{
|
||||
@@ -181,15 +187,15 @@ namespace ZelWiki.Repository
|
||||
allTokens.AddRange(fuzzyTokens);
|
||||
|
||||
return allTokens
|
||||
.GroupBy(token => token.PageId)
|
||||
.Where(group => group.Sum(g => g.Score) >= minimumMatchScore) // Filtering groups
|
||||
.Select(group => new PageSearchToken
|
||||
{
|
||||
PageId = group.Key,
|
||||
Match = group.Max(g => g.Match),
|
||||
Weight = group.Max(g => g.Weight),
|
||||
Score = group.Max(g => g.Score)
|
||||
}).ToList();
|
||||
.GroupBy(token => token.PageId)
|
||||
.Where(group => group.Sum(g => g.Score) >= minimumMatchScore)
|
||||
.Select(group => new PageSearchToken
|
||||
{
|
||||
PageId = group.Key,
|
||||
Match = group.Max(g => g.Match),
|
||||
Weight = group.Max(g => g.Weight),
|
||||
Score = group.Max(g => g.Score)
|
||||
}).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -204,7 +210,7 @@ namespace ZelWiki.Repository
|
||||
return new List<Page>();
|
||||
}
|
||||
|
||||
bool allowFuzzyMatching = ConfigurationRepository.Get<bool>("Search", "Allow Fuzzy Matching");
|
||||
var allowFuzzyMatching = ConfigurationRepository.Get<bool>("Search", "Allow Fuzzy Matching");
|
||||
var meteredSearchTokens = GetMeteredPageSearchTokens(searchTerms, allowFuzzyMatching == true);
|
||||
if (meteredSearchTokens.Count == 0)
|
||||
{
|
||||
@@ -224,7 +230,8 @@ namespace ZelWiki.Repository
|
||||
});
|
||||
}
|
||||
|
||||
public static List<Page> PageSearchPaged(List<string> searchTerms, int pageNumber, int? pageSize = null, bool? allowFuzzyMatching = null)
|
||||
public static List<Page> PageSearchPaged(List<string> searchTerms, int pageNumber, int? pageSize = null,
|
||||
bool? allowFuzzyMatching = null)
|
||||
{
|
||||
if (searchTerms.Count == 0)
|
||||
{
|
||||
@@ -256,7 +263,8 @@ namespace ZelWiki.Repository
|
||||
});
|
||||
}
|
||||
|
||||
public static List<RelatedPage> GetSimilarPagesPaged(int pageId, int similarity, int pageNumber, int? pageSize = null)
|
||||
public static List<RelatedPage> GetSimilarPagesPaged(int pageId, int similarity, int pageNumber,
|
||||
int? pageSize = null)
|
||||
{
|
||||
pageSize ??= ConfigurationRepository.Get<int>("Customization", "Pagination Size");
|
||||
|
||||
@@ -364,7 +372,8 @@ namespace ZelWiki.Repository
|
||||
});
|
||||
}
|
||||
|
||||
public static List<NonexistentPage> GetMissingPagesPaged(int pageNumber, string? orderBy = null, string? orderByDirection = null)
|
||||
public static List<NonexistentPage> GetMissingPagesPaged(int pageNumber, string? orderBy = null,
|
||||
string? orderByDirection = null)
|
||||
{
|
||||
int pageSize = ConfigurationRepository.Get<int>("Customization", "Pagination Size");
|
||||
|
||||
@@ -478,17 +487,18 @@ namespace ZelWiki.Repository
|
||||
return ManagedDataStorage.Pages.Ephemeral(o =>
|
||||
{
|
||||
using var users_db = o.Attach("users.db", "users_db");
|
||||
var query = RepositoryHelper.TransposeOrderby("GetAllNamespacePagesPaged.sql", orderBy, orderByDirection);
|
||||
var query = RepositoryHelper.TransposeOrderby("GetAllNamespacePagesPaged.sql", orderBy,
|
||||
orderByDirection);
|
||||
return o.Query<Page>(query, param).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unlike the search, this method returns all pages and allows them to be paired down using the search terms.
|
||||
/// Whereas the search requires a search term to get results. The matching here is also exact, no score based matching.
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pageNumber"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <param name="orderBy"></param>
|
||||
/// <param name="orderByDirection"></param>
|
||||
/// <param name="searchTerms"></param>
|
||||
/// <returns></returns>
|
||||
public static List<Page> GetAllPagesPaged(int pageNumber,
|
||||
@@ -512,7 +522,8 @@ namespace ZelWiki.Repository
|
||||
using var deletedpagerevisions_db = o.Attach("deletedpagerevisions.db", "deletedpagerevisions_db");
|
||||
using var tempTable = o.CreateTempTableFrom("TempPageIds", pageIds);
|
||||
|
||||
var query = RepositoryHelper.TransposeOrderby("GetAllPagesByPageIdPaged.sql", orderBy, orderByDirection);
|
||||
var query = RepositoryHelper.TransposeOrderby("GetAllPagesByPageIdPaged.sql", orderBy,
|
||||
orderByDirection);
|
||||
return o.Query<Page>(query, param).ToList();
|
||||
});
|
||||
}
|
||||
@@ -528,11 +539,11 @@ namespace ZelWiki.Repository
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unlike the search, this method returns all pages and allows them to be paired down using the search terms.
|
||||
/// Whereas the search requires a search term to get results. The matching here is also exact, no score based matching.
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pageNumber"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <param name="orderBy"></param>
|
||||
/// <param name="orderByDirection"></param>
|
||||
/// <param name="searchTerms"></param>
|
||||
/// <returns></returns>
|
||||
public static List<Page> GetAllDeletedPagesPaged(int pageNumber, string? orderBy = null,
|
||||
@@ -554,7 +565,8 @@ namespace ZelWiki.Repository
|
||||
using var users_db = o.Attach("users.db", "users_db");
|
||||
using var tempTable = o.CreateTempTableFrom("TempPageIds", pageIds);
|
||||
|
||||
var query = RepositoryHelper.TransposeOrderby("GetAllDeletedPagesByPageIdPaged.sql", orderBy, orderByDirection);
|
||||
var query = RepositoryHelper.TransposeOrderby("GetAllDeletedPagesByPageIdPaged.sql", orderBy,
|
||||
orderByDirection);
|
||||
return o.Query<Page>(query, param).ToList();
|
||||
});
|
||||
}
|
||||
@@ -567,7 +579,8 @@ namespace ZelWiki.Repository
|
||||
});
|
||||
}
|
||||
|
||||
public static List<NamespaceStat> GetAllNamespacesPaged(int pageNumber, string? orderBy = null, string? orderByDirection = null)
|
||||
public static List<NamespaceStat> GetAllNamespacesPaged(int pageNumber, string? orderBy = null,
|
||||
string? orderByDirection = null)
|
||||
{
|
||||
int pageSize = ConfigurationRepository.Get<int>("Customization", "Pagination Size");
|
||||
|
||||
@@ -683,6 +696,7 @@ namespace ZelWiki.Repository
|
||||
WikiCache.Put(cacheKey, result);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -719,31 +733,27 @@ namespace ZelWiki.Repository
|
||||
|
||||
try
|
||||
{
|
||||
int currentPageRevision = 0;
|
||||
bool hasPageChanged = false;
|
||||
var currentPageRevision = 0;
|
||||
var hasPageChanged = false;
|
||||
|
||||
if (page.Id == 0)
|
||||
{
|
||||
//This is a new page, just insert it.
|
||||
page.Id = o.ExecuteScalar<int>("CreatePage.sql", pageUpsertParam);
|
||||
hasPageChanged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Get current page so we can determine if anything has changed.
|
||||
var currentRevisionInfo = GetLimitedPageInfoByIdAndRevision(page.Id)
|
||||
?? throw new Exception("The page could not be found.");
|
||||
?? throw new Exception("The page could not be found.");
|
||||
|
||||
currentPageRevision = currentRevisionInfo.Revision;
|
||||
|
||||
//Update the existing page.
|
||||
o.Execute("UpdatePage.sql", pageUpsertParam);
|
||||
|
||||
//Determine if anything has actually changed.
|
||||
hasPageChanged = currentRevisionInfo.Name != page.Name
|
||||
|| currentRevisionInfo.Namespace != page.Namespace
|
||||
|| currentRevisionInfo.Description != page.Description
|
||||
|| currentRevisionInfo.DataHash != newDataHash;
|
||||
|| currentRevisionInfo.Namespace != page.Namespace
|
||||
|| currentRevisionInfo.Description != page.Description
|
||||
|| currentRevisionInfo.DataHash != newDataHash;
|
||||
}
|
||||
|
||||
if (hasPageChanged)
|
||||
@@ -755,7 +765,6 @@ namespace ZelWiki.Repository
|
||||
PageId = page.Id,
|
||||
PageRevision = currentPageRevision
|
||||
};
|
||||
//The page content has actually changed (according to the checksum), so we will bump the page revision.
|
||||
o.Execute("UpdatePageRevisionNumber.sql", updatePageRevisionNumberParam);
|
||||
|
||||
var InsertPageRevisionParam = new
|
||||
@@ -770,7 +779,6 @@ namespace ZelWiki.Repository
|
||||
ModifiedByUserId = page.ModifiedByUserId,
|
||||
ModifiedDate = DateTime.UtcNow,
|
||||
};
|
||||
//Insert the new actual page revision entry (this is the data).
|
||||
o.Execute("InsertPageRevision.sql", InsertPageRevisionParam);
|
||||
|
||||
var reassociateAllPageAttachmentsParam = new
|
||||
@@ -778,7 +786,6 @@ namespace ZelWiki.Repository
|
||||
PageId = page.Id,
|
||||
PageRevision = currentPageRevision,
|
||||
};
|
||||
//Associate all page attachments with the latest revision.
|
||||
o.Execute("ReassociateAllPageAttachments.sql", reassociateAllPageAttachmentsParam);
|
||||
}
|
||||
|
||||
@@ -795,7 +802,7 @@ namespace ZelWiki.Repository
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the page info without the content.
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="navigation"></param>
|
||||
/// <returns></returns>
|
||||
@@ -1001,7 +1008,8 @@ namespace ZelWiki.Repository
|
||||
{
|
||||
using var users_db = o.Attach("users.db", "users_db");
|
||||
|
||||
var query = RepositoryHelper.TransposeOrderby("GetDeletedPageRevisionsByIdPaged.sql", orderBy, orderByDirection);
|
||||
var query = RepositoryHelper.TransposeOrderby("GetDeletedPageRevisionsByIdPaged.sql", orderBy,
|
||||
orderByDirection);
|
||||
return o.Query<DeletedPageRevision>(query, param).ToList();
|
||||
});
|
||||
}
|
||||
@@ -1083,7 +1091,8 @@ namespace ZelWiki.Repository
|
||||
});
|
||||
}
|
||||
|
||||
public static Page? GetPageRevisionByNavigation(string givenNavigation, int? revision = null, bool allowCache = true)
|
||||
public static Page? GetPageRevisionByNavigation(string givenNavigation, int? revision = null,
|
||||
bool allowCache = true)
|
||||
{
|
||||
var navigation = new NamespaceNavigation(givenNavigation);
|
||||
|
||||
@@ -1172,4 +1181,4 @@ namespace ZelWiki.Repository
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user