嘿所有,如果你曾经发表过[craigslist],这个问题应该对你有意义.每当您发布商品(例如,出售家具或公寓)时,您的商家信息不会立即被列入网站.相反,列表将每10-15分钟分批出现(数量不同).起初我真的过度思考这种行为,试图保存记录然后进行批量插入,但我意识到它更简单.在与一些同事交谈之后,Craigslist正在缓存他们的页面然后每10-15分钟清空一次缓存就有意义了.这严重降低了数据库的负载.
现在,我的问题.我如何在Rails中完成同样的事情?我知道如何实现缓存 - 我已经阅读了[使用Rails指南进行缓存].我将使用动作缓存和片段缓存(因为我无法缓存整个页面).我仍然需要进行验证和访问控制,所以我无法完全缓存页面...
我有一个应用程序,我想在Heroku上托管.它有敏感的数据库信息,我不想把它推入github上的公共仓库...但是,我无法将它添加到gitignore文件中,因为它不会被推送到heroku.
是否有可能有一个条件gitignore,我忽略了原始的YML文件,但不是heroku?
我正在使用Ruby和Rails开发IMAP客户端.我可以成功导入邮件,邮箱等...但是,在初始导入后,如何检测自上次同步以来发生的任何更改?
目前,我将UID和UID有效值存储在数据库中,进行比较,并进行适当的搜索.这有效,但它不会检测已删除的消息或对消息标志的更改等.
我是否必须每次都提取所有消息以检测这些更改?其他IMAP客户如何快速完成(即Apple Mail和Postbox).我的脚本每个帐户已经花了10多秒,只有很少的电子邮件地址:
# select ourself as the current mailbox
@imap_connection.examine(self.location)
# grab all new messages and update them in the database
# if the uid's are still valid, we will just fetch the newest UIDs
# otherwise, we need to search when we last synced, which is slower :(
if self.uid_validity.nil? || uid_validity == self.uid_validity
# for some IMAP servers, if a mailbox is empty, a uid_fetch will fail, so then
begin
messages = @imap_connection.uid_fetch(uid_range, ['UID', 'RFC822', 'FLAGS']) …Run Code Online (Sandbox Code Playgroud) 我正在尝试在PostgreSQL中编写一个查询,我有点沮丧,因为它适用于其他数据库引擎.我需要从给定的连接表中选择前5个用户,如下所示:
SELECT users.*,
COUNT(deals.id) AS num_deals
FROM users, deals
WHERE deals.users_id = users.id
GROUP BY users.id
ORDER BY num_deals LIMIT 5;
我需要前5名用户.此代码适用于sqlite,mysql等,但PostgreSQL拒绝选择未在聚合函数中使用的其他字段.我收到以下错误:
PGError: ERROR: column "users.id" must appear in the GROUP BY clause or be used in an aggregate function
Run Code Online (Sandbox Code Playgroud)
我怎么能在PostgreSQL中做到这一点?
我很新Chef.我有一个安装配方,sendmail它完成我的配置.我注意到Chef每次运行都会重启服务.那是因为我正在运行一个execute调用会话重启的人.
它看起来像这样:
execute "hashAccess" do
command "makemap hash /etc/mail/access < /etc/mail/access"
notifies :restart, "service[sendmail]"
end
Run Code Online (Sandbox Code Playgroud)
我只有在access文件更新时才需要调用它.
template "/etc/mail/access" do
source "access.erb"
mode "0644"
notifies :run, "execute[hashAccess]"
end
Run Code Online (Sandbox Code Playgroud)
更新文件时,execute会调用两次.两个资源都在同一个配方中,当我尝试define hashAccess收到错误时
ERROR: Cannot find a resource for define on amazon version 2013.09
Run Code Online (Sandbox Code Playgroud)
如何使执行资源仅在被调用时运行?
我正在尝试运行ChefSpec测试.
这是我的ChefSpec测试:
require_relative '../spec_helper'
describe 'my-demo::basesystem' do
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe)}
describe 'basesystem' do
it "should be installed" do
expect(chef_run).to install_package('build-essential')
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是我的秘诀
include_recipe 'build-essential::default'
Run Code Online (Sandbox Code Playgroud)
这是我执行ChefSpec测试时的错误输出
================================================================================
Recipe Compile Error in /tmp/d20140208-11211-1tu0tmq/my-demo/recipes/basesystem.rb
================================================================================
Chef::Exceptions::CookbookNotFound
----------------------------------
Cookbook build-essential:: not found. If you're loading build-essential:: from another cookbook, make sure you configure the dependency in your metadata
Cookbook Trace:
---------------
/tmp/d20140208-11211-1tu0tmq/build-essential/recipes/default.rb:21:in `from_file'
/tmp/d20140208-11211-1tu0tmq/my-demo/recipes/basesystem.rb:2:in `from_file'
Relevant File Content:
----------------------
/tmp/d20140208-11211-1tu0tmq/build-essential/recipes/default.rb:
14: # distributed under the License is distributed on an "AS IS" …Run Code Online (Sandbox Code Playgroud) 我被困在尝试创建我的第一个lwrp
我创建了一个非常基本的资源+提供者:
resources/rack_site.rb
providers/rack_site.rb
Run Code Online (Sandbox Code Playgroud)
我一直在尝试在同一个食谱的配方中测试'rack_site'资源,但是它失败并且找不到有关资源的错误.我尝试将这两个文件移动到我作为依赖项添加的食谱中,但仍然失败.
将自定义资源用于配方必须做些什么?
如果我遵循云构建文档,我必须在 cloudbuild.yaml 上指定加密的秘密。
secrets:
- kmsKeyName: projects/[PROJECT-ID]/locations/global/keyRings/[KEYRING-NAME]/cryptoKeys/[KEY-NAME]
secretEnv:
MY_SECRET: <base64-encoded encrypted secret>
Run Code Online (Sandbox Code Playgroud)
即使它是加密的,我也不会在代码中提交秘密值。请告诉我另一种方式。
前任。通过来自 gcloud 的 args 构建提交命令或环境变量等
gcloud google-cloud-kms google-cloud-build google-secret-manager
如果我有这样的嵌套资源:
resources :users
resources :posts
end
Run Code Online (Sandbox Code Playgroud)
和a user has_many posts,Rails可以根据URL中的父关联开始编号吗?例如,目前,嵌套资源只是获取ID:
@user.posts.find(params[:id])
Run Code Online (Sandbox Code Playgroud)
这正确命名空间的帖子,只允许来自@user...但是,有没有一种方式使其post_id独立?IE我希望每个用户的帖子从1开始,其中:
/users/1/posts/1
/users/2/posts/1
Run Code Online (Sandbox Code Playgroud)
实际上是指两个不同的帖子?
在我的应用程序中,我想创建在“!”下命名的静态页面。(感叹号)。例如:
/!/about
/!/faq
Run Code Online (Sandbox Code Playgroud)
目前,我可以pages在routes.rb文件中使用前缀来实现此功能:
# config/routes.rb
get 'pages(/:action)' => 'pages', :as => :page
Run Code Online (Sandbox Code Playgroud)
这很好用,并生成正确的URL等。但是,如果我替换pages为!,则路由失败:
# config/routes.rb
get '!(/:action)'...
Run Code Online (Sandbox Code Playgroud)
这是的输出rake routes:
pages GET /!(.:format) {:controller=>"pages", :action=>"index"}
page GET /!/:action(.:format) {:controller=>"pages"}
Run Code Online (Sandbox Code Playgroud)
如您所见,Rails正在生成路线。但是,当我尝试在视图中使用任何那些命名的路由时,都会收到路由错误:
No route matches {:controller => "pages", :action => "about"}
Run Code Online (Sandbox Code Playgroud)
具有讽刺意味的是,如果我使用任何其他符号(如@),则这些路由将按预期工作。我为什么不能!在路线中使用感叹号:(。我应该在github上提交问题吗?
PS,如果我手动指定{:controller => :pages, :action => :about}相同错误的路由,它也会失败。
如果直接访问(/!/about)会呈现正确的页面,则PSS路线实际有效。URL助手只是不允许它实际创建链接:(
chef-infra ×2
ruby ×2
berkshelf ×1
caching ×1
chef-recipe ×1
chefspec ×1
database ×1
deployment ×1
gcloud ×1
git ×1
heroku ×1
imap ×1
lwrp ×1
optimization ×1
postgresql ×1
routes ×1
rspec ×1
uid ×1