向Blog App添加选项,以显示“更多浏览的帖子”

问题描述 投票:0回答:1

实际上,博客帖子对于2sxc来说是一个非常不错的应用程序,但是每次用户打开博客时都能够注册,然后具有一个模块来显示例如5个其他已查看的帖子,这应该很棒。

基本上,我需要知道每次用户打开时如何更新帖子字段(例如,视图)或查看该帖子的详细信息

感谢您的帮助

2sxc
1个回答
0
投票

这是一个有趣的主意-让我为您提供一些基本指导,以确保一切正常...

  1. 首先,我真的建议您在单独的项目/实体中进行计数。这是出于性能方面的考虑:更新博客文章时,您要更新20-30个字段,这只会给系统带来很多不必要的压力。因此,使用属性ViewCountBlogPostId]创建类似Count的东西>
  2. 现在更新计数,我建议您做两件事
    1. 获取计数并将其缓存在某处
    2. 更新每个视图上的缓存计数
    3. 仅每隔或每点击100次更新服务器数据(仅出于性能考虑,我认为您希望获得很多观看结果)] >>

这里有一些伪代码要执行此操作...

var postId = post.EntityId;
var cacheId = "PostCount" + postId;
var count = Application[cacheId] ?? -1;
if(count == -1) {
  // load the data
  var countStates = AsList(App.Data["ViewCount"]);
  var counter = countStates.FirstOrDefault(c => c.BlogPostId == postId);
  if(counter != null) {
    count = counter.Count;
  } else {
    count = 0;
  }
}

// increment
count++;

// save to cache
Application[cacheId] = count;

// every 10 counts update the count in the storage / sql
// on high load, increase this to 100 or 1000
if(count % 10 == 0) {
  // you'll have to figure this out yourself - see docs link below
  App.Data.Update(...);
}

为了保存,请在https://docs.2sxc.org/api/dot-net/ToSic.Eav.Apps.AppData.html#ToSic_Eav_Apps_AppData_Update_System_Int32_System_Collections_Generic_Dictionary_System_String_System_Object__System_String_中查看文档>

© www.soinside.com 2019 - 2024. All rights reserved.