Skip to content
This repository has been archived by the owner on Sep 2, 2019. It is now read-only.

Commit

Permalink
Moved limit to a redis server-side sort
Browse files Browse the repository at this point in the history
  • Loading branch information
whoahbot committed Feb 4, 2010
1 parent 5f6abc3 commit 4c73796
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2009 Dan Herrera
Copyright (c) 2010 Dan Herrera

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'dm-core'
require 'benchmark'
require 'redis'
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/dm_redis_adapter.rb'))
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/dm_redis.rb'))

class Post
include DataMapper::Resource
Expand Down
11 changes: 5 additions & 6 deletions lib/dm_redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def read(query)
end

records = query.match_records(records)
records = query.limit_records(records)
records = query.sort_records(records)
records
end
Expand Down Expand Up @@ -141,11 +140,11 @@ def records_for(query)
end
end

# if query.limit
# @redis.sort("#{query.model.to_s.downcase}:#{redis_key_for(query.model)}:all", :limit => [query.offset, query.limit]).each do |val|
# keys << {"#{redis_key_for(query.model)}" => val.to_i}
# end
# end
if query.limit
@redis.sort("#{query.model.to_s.downcase}:#{redis_key_for(query.model)}:all", :limit => [query.offset, query.limit]).each do |val|
keys << {"#{redis_key_for(query.model)}" => val.to_i}
end
end

# Keys are empty, fall back and load all the values for this model
if keys.empty?
Expand Down

0 comments on commit 4c73796

Please sign in to comment.