mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 17:08:34 +00:00
Feature: Memoize firestore connection
This commit is contained in:
parent
bb089d8ab3
commit
6f0e65cb93
1 changed files with 16 additions and 6 deletions
|
|
@ -1,10 +1,12 @@
|
|||
class FirestoreQueryService
|
||||
require 'google/cloud/firestore'
|
||||
include DatasourceUtils
|
||||
|
||||
attr_accessor :data_query, :options, :source_options, :current_user
|
||||
attr_accessor :data_query, :options, :source_options, :current_user, :data_source
|
||||
|
||||
def initialize(data_query, options, source_options, current_user)
|
||||
@data_query = data_query
|
||||
@data_source = data_query.data_source
|
||||
@options = options
|
||||
@source_options = source_options
|
||||
@current_user = current_user
|
||||
|
|
@ -23,16 +25,13 @@ class FirestoreQueryService
|
|||
end
|
||||
|
||||
def process
|
||||
credential_json = JSON.parse(source_options['gcp_key'])
|
||||
data = {}
|
||||
error = nil
|
||||
|
||||
begin
|
||||
Google::Cloud::Firestore.configure do |config|
|
||||
config.credentials = credential_json
|
||||
end
|
||||
|
||||
firestore = Google::Cloud::Firestore.new
|
||||
firestore = get_cached_connection(data_source)
|
||||
firestore = create_connection unless firestore
|
||||
|
||||
operation = data_query.options['operation']
|
||||
|
||||
|
|
@ -107,4 +106,15 @@ class FirestoreQueryService
|
|||
doc_ref = firestore.doc path
|
||||
doc_ref.update body
|
||||
end
|
||||
|
||||
def create_connection
|
||||
credential_json = JSON.parse(source_options['gcp_key'])
|
||||
Google::Cloud::Firestore.configure do |config|
|
||||
config.credentials = credential_json
|
||||
end
|
||||
firestore = Google::Cloud::Firestore.new
|
||||
|
||||
cache_connection(data_source, firestore)
|
||||
firestore
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue