如何在Orchard中删除内容项的版本记录? [英] How to delete version records of a content item in Orchard?

查看:90
本文介绍了如何在Orchard中删除内容项的版本记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行与用户同步相关的Orchard CMS.此同步功能会在一夜之间更新每个用户,并且代码以

I have a Orchard CMS running that is tied to a user synchronization. This sync updates each user overnight and the code begins with

... = mContentManager.Get<Orchard.Users.Models.UserPart>(lOrchardUser.ContentItem.Id,
  Orchard.ContentManagement.VersionOptions.DraftRequired);

如您所见,每次用户同步时,VersionOptions.DraftRequired都会传递给Get()方法,并创建一个新的草稿.它不是要在此处创建新的草稿,因此我将其更改为VersionOptions.Published,这避免了在每次调用时创建新的版本记录.

As you can see VersionOptions.DraftRequired is passed to the Get() method with creates a new draft each time the user is synchronized. It's not intended to create a new draft here so i changed it to VersionOptions.Published which avoids creating a new version record on each call.

但是这里的问题是,过去传递VersionOptions.DraftRequired会为每个用户创建大约120个版本记录,而数据库中大约有1000个用户.

But issue here is that passing VersionOptions.DraftRequired in the past has created around 120 version records for each user whereas there are around 1000 users in the DB.

当我现在使用IContentManager.Query()时,由于版本很多,花费的时间要长得多.

When i now use IContentManager.Query() it takes considerably longer due to the high amount of versions.

我的想法是删除所有已发布的版本,因为我不需要它们,但IContentManager不提供任何版本删除选项,并且使用IRepository<>删除记录会导致NHibernate异常.

My idea is to remove all versions except the published one as i don't need them but IContentManager doesn't provide any version removal option and deleting the records by using IRepository<> causes a NHibernate exception.

所以我最后的选择是使用LINQ查询删除版本,这确实可行,但是我被告知不建议在Orchard中使用LINQ.

So my last resort was to use LINQ queries to remove the versions, this did work but i was told that using LINQ in Orchard is not recommended.

我想知道是否有人在版本记录数量上有任何问题,因为系统运行的时间越长,累积的数据就越多,并且系统的运行速度越来越慢.

I wonder whether anyone had any issues with high amounts of version records as the longer the system runs the more data is accumulated and the system is getting slower and slower.

所以,我的问题是

  1. 是否有Orchard方式删除版本记录?
  2. 是否可以禁用版本控制?

推荐答案

由于似乎没有Orchard方法可以执行此操作,因此我使用以下LINQ 2 SQL代码删除了这些版本:

As there seems no Orchard way to do this, i deleted the versions with the following LINQ 2 SQL code:

  public System.Web.Mvc.ActionResult RemoveVersions()
  {
    // select user ids, an alternate way is to retrieve user IDs via content manager but this takes a veeeeery long time due
    // to the need of querying all versions
    //
    // var lOrchardUserIDs = mContentManager
    //  .Query<Orchard.Users.Models.UserPart, Orchard.Users.Models.UserPartRecord>(Orchard.ContentManagement.VersionOptions.AllVersions)
    //  .List()
    //  .Select(u => u.Id)
    //  .ToList()
    var lOrchardUserIDs = mUserRepository.Fetch(u => true).Select(u => u.Id).ToList();

    foreach (var lOrchardUserID in lOrchardUserIDs)
    {
      var lContentItemVersionRecords =
        (from r in DataContext.ContentItemVersionRecords where r.ContentItemRecord_id == lOrchardUserID select r).ToList();

      if (lContentItemVersionRecords.Count > 1)
      {
        foreach (var lContentItemVersionRecord in lContentItemVersionRecords)
        {
          if (lContentItemVersionRecord.Number == 1)
          {
            if (lContentItemVersionRecords[lContentItemVersionRecords.Count - 1].Published)
            {
              lContentItemVersionRecord.Latest = true;
              lContentItemVersionRecord.Published = true;
            }
          }
          else
            DataContext.ContentItemVersionRecords.DeleteOnSubmit(lContentItemVersionRecord);
        }
      }
    }

    DataContext.SubmitChanges();

    return Content("Done");
  }

这篇关于如何在Orchard中删除内容项的版本记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆