Rails 3 - 文件名太长错误

发布于 2024-10-31 23:50:31 字数 538 浏览 0 评论 0原文

我们有一个在 Rails 3 Spree 平台上运行的在线商店。最近,客户在结帐期间开始报告奇怪的错误,在分析生产日志后,我发现以下错误:

Errno::ENAMETOOLONG(文件名太长 - /var/www/store/tmp/cache/UPS-R43362140-US-NJ-FlorhamPark07932-1025786194_1%7C1025786087_1%7C1025786089_15%7C1025786146_4%7C1025786147_3%7C1025786098_3%7C1025786099_4%7C1025786100_2%7C1025786114_1%7C1025786120_1%7C1025786121_1%7C1025786181_1%7C1025786182_1%7C1025786208_120110412-2105-1e14pq5.lock)

I'm not sure why this file name太长了,如果这个错误是 Rails 或 Spree 特有的。另外我对 Rails 缓存系统不是很熟悉。对于如何解决此问题的任何帮助,我将不胜感激。

We have an online store running on Rails 3 Spree platform. Recently customers started reporting weird errors during checkout and after analyzing production logs I found the following error:

Errno::ENAMETOOLONG (File name too long - /var/www/store/tmp/cache/UPS-R43362140-US-NJ-FlorhamPark07932-1025786194_1%7C1025786087_1%7C1025786089_15%7C1025786146_4%7C1025786147_3%7C1025786098_3%7C1025786099_4%7C1025786100_2%7C1025786114_1%7C1025786120_1%7C1025786121_1%7C1025786181_1%7C1025786182_1%7C1025786208_120110412-2105-1e14pq5.lock)

I'm not sure why this file name is so long and if this error is specific to Rails or Spree. Also I'm not very familiar with Rails caching system. I would appreciate any help on how I can resolve this problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

感性 2024-11-07 23:50:31

我猜您正在使用 spree_active_shipping,因为它看起来像 UPS 运输报价的缓存 ID。当有人创建包含大量订单项的订单时,就会发生这种情况。如果有足够的行项目,这当然会为缓存创建一个非常大的文件名,从而给您带来错误。

一种选择是为 Rails.cache 使用 memcache 或 redis,而不是使用文件系统缓存。另一种方法是修改 spree_active_shipping gem 中 app/models/active_shipping.rb 中生成 cache_key 的算法。

后一个选项可能是最好的,您可以简单地让生成的缓存密钥通过 MD5 或 SHA1 等哈希运行。这样您将获得可预测的缓存密钥长度。

实际上,这应该在 spree_active_shipping 中修复,但它不应该生成不可预测的长缓存键,即使您使用键值存储,这也会浪费内存。

I'm guessing you are using spree_active_shipping, as that looks like a cache id for a UPS shipping quote. This will happen when someone creates an order that has a lot of line items in it. With enough line items this will of course create a very large filename for the cache, thus giving you the error.

One option would be to use memcache or redis for your Rails.cache instead of using the filesystem cache. Another would be to modify the algorithm that generates the cache_key within app/models/active_shipping.rb in the spree_active_shipping gem.

The latter option would probably be best, and you could simply have the generated cache key run through a hash like MD5 or SHA1. This way you'll get predictable cache key lengths.

Really this should be fixed within spree_active_shipping though, it shouldn't be generating unpredictably long cache keys, even if you a key-value store is used, that's wasted memory.

攒一口袋星星 2024-11-07 23:50:31

和你的文件系统关系更大。要么设置一个支持更长文件名的文件系统,要么更改软件以生成更好的(md5?时间戳?唯一ID?)文件名。

It is more related to your file system. Either set up a file system which supports longer file names or change the software to make better (md5?timestamp?unique id?) file names.

呢古 2024-11-07 23:50:31

可能是这样的帮助:

config.assets.digestconfig.assets.debug 不能同时为 true

这是一个错误:https://github.com/rails/jquery-rails/issues/33

May be this help:

config.assets.digest and config.assets.debug can't both be true

It's a bug : https://github.com/rails/jquery-rails/issues/33

南冥有猫 2024-11-07 23:50:31

我正在使用 Rails 3.2.x 并遇到同样的问题。我最终在用于生成缓存密钥的视图帮助器方法中生成 MD5 摘要。

FILENAME_MAX_SIZE = 200    
def cache_key(prefix, params)
  params = Array.wrap(params) if params.instance_of?(String)
  key = "#{prefix}/" << params.entries.sort { |a,b| a[0].to_s <=> b[0].to_s }.map { |k,v| "#{k}:#{v}"}.join(',').to_s
  if URI.encode_www_form_component(key).size > FILENAME_MAX_SIZE
    key = Digest::MD5.hexdigest(key)
  end
  key
end

在这里,我必须使用 URI.encode_www_form_component(key).size 检查 URI 编码键值的长度,因为正如您在我的例子中看到的,缓存键是使用 : 生成的,并且, 分隔符。 Rails 在缓存结果之前对密钥进行编码。

我参考了拉取请求

I am using rails 3.2.x and having same issue. I end up generating MD5 digest in the view helper method used to generate cache key.

FILENAME_MAX_SIZE = 200    
def cache_key(prefix, params)
  params = Array.wrap(params) if params.instance_of?(String)
  key = "#{prefix}/" << params.entries.sort { |a,b| a[0].to_s <=> b[0].to_s }.map { |k,v| "#{k}:#{v}"}.join(',').to_s
  if URI.encode_www_form_component(key).size > FILENAME_MAX_SIZE
    key = Digest::MD5.hexdigest(key)
  end
  key
end

Here I have to check length of URI encoded key value using URI.encode_www_form_component(key).size because as you can see in my case, cache key is generated using : and , separators. Rails encodes the key before caching the results.

I took reference from the pull request.

送你一个梦 2024-11-07 23:50:31

您使用回形针宝石吗?如果是,则此问题已解决: https://github.com/thoughtbot/paperclip/issues/1246

请将您的回形针 gem 更新到最新版本。

Are you using paperclip gem? If yes, this issue is solved: https://github.com/thoughtbot/paperclip/issues/1246.

Please update your paperclip gem to the latest version.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文