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:
parent
7f652e9d7f
commit
e19ee93ee3
4 changed files with 65 additions and 38 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue