Skip to content

Commit d3a57b6

Browse files
committed
Add comment that explains what happens
1 parent 39530ac commit d3a57b6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

app/models/solid_cache/entry.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ def upsert_unique_by
9292
connection.supports_insert_conflict_target? ? :key_hash : nil
9393
end
9494

95+
# This constructs and caches a SQL query for a given number of keys.
96+
#
97+
# The query is constructed with two bind parameters to generate an IN (...) condition,
98+
# which is then replaced with the correct amount based on the number of keys. The
99+
# parameters are filled later when executing the query. This is done through Active Record
100+
# to ensure the field and table names are properly quoted and escaped based on the used database adapter.
101+
102+
# For example: The query for 4 keys will be transformed from:
103+
# > SELECT "key", "value" FROM "solid_cache_entries" WHERE "key_hash" IN (1111, 2222)
104+
# into:
105+
# > SELECT "key", "value" FROM "solid_cache_entries" WHERE "key_hash" IN (?, ?, ?, ?)
95106
def select_sql(keys)
96107
@select_sql ||= {}
97108
@select_sql[keys.count] ||= \

0 commit comments

Comments
 (0)