2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-07 12:02:53 +08:00

Stop using OFFSET in DB queries of phpBB3 importer

http://use-the-index-luke.com/no-offset
This commit is contained in:
Gerhard Schlager 2016-01-14 22:43:19 +01:00
parent 7f652e9d7f
commit e19ee93ee3
No known key found for this signature in database
GPG key ID: 7DACA3C95B36014B
4 changed files with 65 additions and 38 deletions

View file

@ -12,13 +12,36 @@ module ImportScripts::PhpBB3
protected
# Executes a database query.
def query(sql)
@database_client.query(sql, cache_rows: true, symbolize_keys: true)
def query(sql, *last_columns)
rows = @database_client.query(sql, cache_rows: true, symbolize_keys: true)
return rows if last_columns.length == 0
result = [rows]
last_row = find_last_row(rows)
last_columns.each { |column| result.push(last_row ? last_row[column] : nil) }
result
end
# Executes a database query and returns the value of the 'count' column.
def count(sql)
query(sql).first[:count]
end
def escape(value)
@database_client.escape(value)
end
private
def find_last_row(rows)
last_index = rows.size - 1
rows.each_with_index do |row, index|
return row if index == last_index
end
nil
end
end
end