首页 \ 问答 \ 何时使用关系数据库结构?(When to use a relational database structure?)

何时使用关系数据库结构?(When to use a relational database structure?)

我正在创建文件托管服务,但是现在我正在创建注册帐户电子邮件激活部分。 所以我不得不想出一个数据库结构。

而现在它是:

users
  id
  first_name
  last_name
  email
  password
  since
  active
  hash_activate

但我也可以像关系数据库那样做:

users
  id
  first_name
  last_name
  email
  password
  since

activation
  id
  user_id
  hash
  active

最好的方法是什么? 为什么?


I'm creating a file hosting service, but right now I am creating the account email activation part of registering. So I had to come up with a database structure.

And right now it's:

users
  id
  first_name
  last_name
  email
  password
  since
  active
  hash_activate

But I can do it like a relational database too:

users
  id
  first_name
  last_name
  email
  password
  since

activation
  id
  user_id
  hash
  active

What would be the best way to go about it? And why?


原文:https://stackoverflow.com/questions/23221967
更新时间:2023-10-05 09:10

最满意答案

由于您正在使用MVC,因此使用一组不同的管道(再次)解析该项目,因此您需要在此处进行修补。

mvc.getPageItem管道中的GetFromRouteUrl处理器将mvc.getPageItem设置为与请求的URL匹配的项,然后最终将其设置为Context.Item ,因此它基本上将项重置为基于URL的“正确”项并覆盖你之前做出的改变。

您需要向mvc.getPageItem添加一个需要处理器,并使用一些逻辑来检查上下文项是否已经解析。

更新ItemResolver中的代码并存储一个布尔值以指示您已使用自定义逻辑解析,这节省了必须运行两次解析逻辑:

public override void Process(HttpRequestArgs args)
{
  // some code
  Context.Item = dropLink.TargetItem;
  Context.Items["custom::ItemResolved"] = true;
}

创建一个新类,检查您的自定义逻辑是否已解析该项:

public class CheckItemResolved: GetPageItemProcessor
{
  public override void Process(GetPageItemArgs args)
  {
    if (args.Result == null)
    {
        var resolved = Sitecore.Context.Items["custom::ItemResolved"];
        if (MainUtil.GetBool(resolved, false))
        {
            // item has previously been resolved
            args.Result = Sitecore.Context.Item;
        }
    }

    return;
  }
}

然后修补此:

<pipelines>
  <mvc.getPageItem>
    <processor type="MyProject.Custom.Pipelines.CheckItemResolved, MyProject.Custom"
        patch:before="*[@type='Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromRouteUrl, Sitecore.Mvc']" />
  </mvc.getPageItem>
</pipelines>

紧接着的管道是GetFromFromUrl() ,它通常args.Result通过重新解析Item来设置args.Result 。 通过将其设置回Context.Item,处理器将提前爆发并保留以前的逻辑。

您可以在文档中找到有关MVC和管道的更多详细信息。


Since you are using MVC the item is resolved (again) using a different set of pipelines, so you need to patch into there instead.

The GetFromRouteUrl processor in the mvc.getPageItem pipeline sets args.Result to the item matching the requested URL which is then eventually set to Context.Item, so it essentially resets the item back to the "correct" item based on the URL and that overwrites the changes you made earlier.

You need to add a need processor to the mvc.getPageItem with some logic to check if the context item has already been resolved.

Update your code in the ItemResolver and store a boolean to indicate that you have already resolved using custom logic, this saves having to run the resolving logic twice:

public override void Process(HttpRequestArgs args)
{
  // some code
  Context.Item = dropLink.TargetItem;
  Context.Items["custom::ItemResolved"] = true;
}

Create a new Class that checks if your custom logic has already resolved the item:

public class CheckItemResolved: GetPageItemProcessor
{
  public override void Process(GetPageItemArgs args)
  {
    if (args.Result == null)
    {
        var resolved = Sitecore.Context.Items["custom::ItemResolved"];
        if (MainUtil.GetBool(resolved, false))
        {
            // item has previously been resolved
            args.Result = Sitecore.Context.Item;
        }
    }

    return;
  }
}

And then patch this in:

<pipelines>
  <mvc.getPageItem>
    <processor type="MyProject.Custom.Pipelines.CheckItemResolved, MyProject.Custom"
        patch:before="*[@type='Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromRouteUrl, Sitecore.Mvc']" />
  </mvc.getPageItem>
</pipelines>

The pipeline immediately after is GetFromFromUrl() which would normally set args.Result by re-resolving the Item. By setting it back to Context.Item that processor will break out early and leave your previous logic alone.

You can find more details about MVC and Pipelines in the documentation.

相关问答

更多
  • Sitecore查询(或快速查询)不支持排序或TOP构造,所以这些东西必须用代码表示。 专注于缓存是一件好事。 使用标准Sitecore渲染缓存是一种最简单的方法,我不认为你需要比这种情况更复杂的东西。 它有助于理解Sitecore查询可以在SQL或API级别解决 ,这会影响性能,有时可以利用您的优势。 快速查询内置到Sitecore 6中,并使所有查询都在SQL级别执行,大大提高了性能。 目前它也不支持排序和TOP,但我们正在考虑如何添加。 Sitecore Query (or a fast query) ...
  • 由于您正在使用MVC,因此使用一组不同的管道(再次)解析该项目,因此您需要在此处进行修补。 mvc.getPageItem管道中的GetFromRouteUrl处理器将mvc.getPageItem设置为与请求的URL匹配的项,然后最终将其设置为Context.Item ,因此它基本上将项重置为基于URL的“正确”项并覆盖你之前做出的改变。 您需要向mvc.getPageItem添加一个需要处理器,并使用一些逻辑来检查上下文项是否已经解析。 更新ItemResolver中的代码并存储一个布尔值以指示您已使用 ...
  • 要从代码中刷新内容树,请使用: //TODO: set to the appropriate item String refresh = String.Format("item:refreshchildren(id={0})", currentItem.Parent.ID); Sitecore.Context.ClientPage.SendMessage(this, refresh); To refresh the content tree from the code use: //TODO: set ...
  • 使用.NET 4.0中引入的HttpResponse.RedirectPermanent方法,不需要sitecore API Use HttpResponse.RedirectPermanent method that was introduced in .NET 4.0, No sitecore API needed
  • 您可以通过执行以下操作来实现此目的: 1-在web.config将此设置设置为true : Authentication.SaveRawUrl 2-创建一个名为LoginRedirect类: using System.Web; using Sitecore.Pipelines.LoggedIn; using Sitecore.Web; namespace Sitecore.SharedResources.Pipelines.Login { public class LoginRedirect : Lo ...
  • 您不需要扩展ExecuteRequest处理器,配置的Sitecore部分中有设置可以处理这些: