inerited channel stats works better

before it would include 1 level, then assume that's the top. so 2 degrees of inheritance would confuse it
This commit is contained in:
Adam R Grey 2024-06-29 16:45:07 -04:00
parent af4d68caa1
commit ab16600463
2 changed files with 38 additions and 20 deletions

View File

@ -27,7 +27,16 @@ public class ChannelsController : Controller
{ {
if(_db.Channels == null) if(_db.Channels == null)
return Problem("Entity set '_db.Channels' is null."); return Problem("Entity set '_db.Channels' is null.");
var channel = await _db.Channels.Include(u => u.SubChannels).Include(u => u.Users).Include(u => u.ParentChannel).FirstAsync(u => u.Id == id); //"but adam", says the strawman, "why load *every* channel and walk your way up? surely there's a .Load command that works or something."
//eh. I checked. Not really. You could make an SQL view that recurses its way up, meh idk how. You could just eagerly load *every* related object...
//but that would take in all the messages.
//realistically I expect this will have less than 1MB of total "channels", and several GB of total messages per (text) channel.
var AllChannels = await _db.Channels
.Include(u => u.SubChannels)
.Include(u => u.Users)
.Include(u => u.ParentChannel)
.ToListAsync();
var channel = AllChannels.First(u => u.Id == id);
var walker = channel; var walker = channel;
while(walker != null) while(walker != null)
{ {
@ -35,7 +44,10 @@ public class ChannelsController : Controller
ViewData["breadcrumbs"]; ViewData["breadcrumbs"];
walker = walker.ParentChannel; walker = walker.ParentChannel;
} }
return View(channel); return View(
new Tuple<Channel, Enumerations.LewdnessFilterLevel, Enumerations.MeannessFilterLevel>(
channel, channel.EffectivePermissions.LewdnessFilterLevel, channel.EffectivePermissions.MeannessFilterLevel
));
} }
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]

View File

@ -1,6 +1,12 @@
@using System.ComponentModel @using System.ComponentModel
@using Newtonsoft.Json @using Newtonsoft.Json
@model Channel @model Tuple<Channel, Enumerations.LewdnessFilterLevel, Enumerations.MeannessFilterLevel>
@{
var ThisChannel = Model.Item1;
var IfInheritedLewdnessFilterLevel = Model.Item2;
var IfInheritedMeannessFilterLevel = Model.Item3;
}
@Html.Raw(ViewData["breadcrumbs"]) @Html.Raw(ViewData["breadcrumbs"])
@ -8,21 +14,21 @@
<tbody> <tbody>
<tr> <tr>
<th scope="row">Display Name</th> <th scope="row">Display Name</th>
<td>@Model.DisplayName</td> <td>@ThisChannel.DisplayName</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Channel type</th> <th scope="row">Channel type</th>
<td>@(Model.ChannelType != null ? Enumerations.GetDescription(Model.ChannelType) : "?")</td> <td>@(ThisChannel.ChannelType != null ? Enumerations.GetDescription(ThisChannel.ChannelType) : "?")</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Lewdness Filter Level</th> <th scope="row">Lewdness Filter Level</th>
<td> <td>
<select name="LewdnessFilterLevel" id="LewdnessFilterLevel" onchange="patchModel(jsonifyChannel())"> <select name="LewdnessFilterLevel" id="LewdnessFilterLevel" onchange="patchModel(jsonifyChannel())">
<!option value="" @(Model.LewdnessFilterLevel == null ? "selected" : "")>inhereted</!option> <!option value="" @(ThisChannel.LewdnessFilterLevel == null ? "selected" : "")>inherited - @Enumerations.GetDescription(IfInheritedLewdnessFilterLevel)</!option>
@foreach (Enumerations.LewdnessFilterLevel enumVal in @foreach (Enumerations.LewdnessFilterLevel enumVal in
Enum.GetValues(typeof(Enumerations.LewdnessFilterLevel))) Enum.GetValues(typeof(Enumerations.LewdnessFilterLevel)))
{ {
<!option value="@((int)enumVal)" @(Model.LewdnessFilterLevel == enumVal ? "selected" : "")> <!option value="@((int)enumVal)" @(ThisChannel.LewdnessFilterLevel == enumVal ? "selected" : "")>
@(Enumerations.GetDescription<Enumerations.LewdnessFilterLevel>(enumVal))</!option> @(Enumerations.GetDescription<Enumerations.LewdnessFilterLevel>(enumVal))</!option>
} }
</select> </select>
@ -30,29 +36,29 @@
</tr> </tr>
<tr> <tr>
<th scope="row">Links Allowed</th> <th scope="row">Links Allowed</th>
<td>@(Model.LinksAllowed?.ToString() ?? "unknown")</td> <td>@(ThisChannel.LinksAllowed?.ToString() ?? "unknown")</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Lineage summary</th> <th scope="row">Lineage summary</th>
<td>@Model.LineageSummary</td> <td>@ThisChannel.LineageSummary</td>
</tr> </tr>
<tr> <tr>
<th scope="row">max attachment bytes</th> <th scope="row">max attachment bytes</th>
<td>@Model.MaxAttachmentBytes (i hear there's "ByteSize")</td> <td>@ThisChannel.MaxAttachmentBytes (i hear there's "ByteSize")</td>
</tr> </tr>
<tr> <tr>
<th scope="row">max message length</th> <th scope="row">max message length</th>
<td>@(Model.MaxTextChars?.ToString() ?? "inherited")</td> <td>@(ThisChannel.MaxTextChars?.ToString() ?? "inherited")</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Meanness Filter Level</th> <th scope="row">Meanness Filter Level</th>
<td> <td>
<select name="MeannessFilterLevel" id="MeannessFilterLevel" onchange="patchModel(jsonifyChannel())"> <select name="MeannessFilterLevel" id="MeannessFilterLevel" onchange="patchModel(jsonifyChannel())">
<!option value="" @(Model.MeannessFilterLevel == null ? "selected" : "")>⤵ inhereted</!option> <!option value="" @(ThisChannel.MeannessFilterLevel == null ? "selected" : "")>⤵ inherited - @Enumerations.GetDescription(IfInheritedMeannessFilterLevel)</!option>
@foreach (Enumerations.MeannessFilterLevel enumVal in @foreach (Enumerations.MeannessFilterLevel enumVal in
Enum.GetValues(typeof(Enumerations.MeannessFilterLevel))) Enum.GetValues(typeof(Enumerations.MeannessFilterLevel)))
{ {
<!option value="@((int)enumVal)" @(Model.MeannessFilterLevel == enumVal ? "selected" : "")> <!option value="@((int)enumVal)" @(ThisChannel.MeannessFilterLevel == enumVal ? "selected" : "")>
@(Enumerations.GetDescription<Enumerations.MeannessFilterLevel>(enumVal))</!option> @(Enumerations.GetDescription<Enumerations.MeannessFilterLevel>(enumVal))</!option>
} }
</select> </select>
@ -60,23 +66,23 @@
</tr> </tr>
<tr> <tr>
<th scope="row">Messages (count)</th> <th scope="row">Messages (count)</th>
<td>@(Model.Messages?.Count ?? 0)</td> <td>@(ThisChannel.Messages?.Count ?? 0)</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Protocol</th> <th scope="row">Protocol</th>
<td>@Model.Protocol</td> <td>@ThisChannel.Protocol</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Reactions Possible</th> <th scope="row">Reactions Possible</th>
<td>@(Model.ReactionsPossible?.ToString() ?? "inherited")</td> <td>@(ThisChannel.ReactionsPossible?.ToString() ?? "inherited")</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Sub Channels</th> <th scope="row">Sub Channels</th>
<td>@(Model.SubChannels?.Count ?? 0)</td> <td>@(ThisChannel.SubChannels?.Count ?? 0)</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Users</th> <th scope="row">Users</th>
<td>@(Model.Users?.Count ?? 0)</td> <td>@(ThisChannel.Users?.Count ?? 0)</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -85,7 +91,7 @@
@section Scripts{ @section Scripts{
<script type="text/javascript"> <script type="text/javascript">
@{ @{
var modelAsString = JsonConvert.SerializeObject(Model, new JsonSerializerSettings var modelAsString = JsonConvert.SerializeObject(ThisChannel, new JsonSerializerSettings
{ {
ReferenceLoopHandling = ReferenceLoopHandling.Ignore ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}); });