Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit a875162

Browse files
committed
fix!(frecency): Use byte strings for DB IDs
1 parent 8ed193e commit a875162

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

lua/legendary/api/db/client.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ function M.update_item_score(item)
8181
M.db_wrapper:update(item)
8282
end
8383

84-
function M.sql_escape(str)
85-
return M.db_wrapper.sql_escape(str)
84+
function M.to_bytes(str)
85+
return M.db_wrapper.to_bytes(str)
8686
end
8787

8888
function M.get_client()

lua/legendary/api/db/wrapper.lua

+7-3
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,18 @@ local function row_id(row)
155155
return (not vim.tbl_isempty(row)) and row[1].id or nil
156156
end
157157

158-
function M.sql_escape(str)
159-
return string.format("'%s'", string.gsub(str, "'", "\\'"))
158+
function M.to_bytes(str)
159+
local result = ''
160+
for c in str:gmatch('.') do
161+
result = result .. string.byte(c)
162+
end
163+
return result
160164
end
161165

162166
---Update the stored data for an item
163167
---@param item LegendaryItem
164168
function M:update(item)
165-
local item_id = M.sql_escape(item:frecency_id())
169+
local item_id = M.to_bytes(item:frecency_id())
166170
Log.trace('Updating item with ID "%s"', item_id)
167171
local entry_id = row_id(self:transaction(self.queries.item_get_entries, { where = { item_id = item_id } }))
168172
if not entry_id then

lua/legendary/data/itemlist.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ function ItemList:sort_inplace(opts)
164164
---@param item1 LegendaryItem
165165
---@param item2 LegendaryItem
166166
function(item1, item2)
167-
local item1_id = DbClient.sql_escape(item1:frecency_id())
168-
local item2_id = DbClient.sql_escape(item2:frecency_id())
167+
local item1_id = DbClient.to_bytes(item1:frecency_id())
168+
local item2_id = DbClient.to_bytes(item2:frecency_id())
169169
local item1_score = frecency_scores[item1_id] or 0
170170
local item2_score = frecency_scores[item2_id] or 0
171171
return item1_score > item2_score

0 commit comments

Comments
 (0)