From e74cb218d5679abb169a5b50e71681240e1b5d50 Mon Sep 17 00:00:00 2001
From: Alexander Olofsson <alexander.olofsson@liu.se>
Date: Fri, 25 Oct 2019 15:10:20 +0200
Subject: [PATCH] Avoid excessive requests for existing data

---
 lib/passwordstate/resource_list.rb | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/passwordstate/resource_list.rb b/lib/passwordstate/resource_list.rb
index beb262d..255b2a4 100644
--- a/lib/passwordstate/resource_list.rb
+++ b/lib/passwordstate/resource_list.rb
@@ -95,6 +95,13 @@ module Passwordstate
     def get(id, query = {})
       raise 'Operation not supported' unless operation_supported?(:get)
 
+      if query.empty?
+        existing = entries.find do |entry|
+          entry.send(entry.class.index_field) == id
+        end
+        return existing if existing
+      end
+
       api_path = options.fetch(:get_path, resource.api_path)
       query = options.fetch(:get_query, {}).merge(query)
 
-- 
GitLab