このコミットが含まれているのは:
2026-06-28 03:40:35 +09:00
コミット ec98c6b756
5個のファイルの変更140行の追加13行の削除
+11 -4
ファイルの表示
@@ -26,13 +26,19 @@ module GoogleDrive
def list_material_files_under_folder folder_id
files = []
each_material_file_under_folder(folder_id) { |entry| files << entry }
files
end
def each_material_file_under_folder folder_id
return enum_for(__method__, folder_id) unless block_given?
walk_folder(folder_id, nil) do |entry, relative_path|
next if entry['mimeType'] == FOLDER_MIME_TYPE
next if native_file?(entry['mimeType'])
files << build_file_entry(entry, relative_path)
yield build_file_entry(entry, relative_path)
end
files
end
def fetch_material_file file_id
@@ -44,9 +50,10 @@ module GoogleDrive
def download_to_tempfile file_id, filename:
tempfile = Tempfile.new(['material-sync', File.extname(filename.to_s)])
tempfile.binmode
request_binary("/files/#{ file_id }",
{ alt: 'media', supportsAllDrives: true }) do |chunk|
tempfile.write(chunk)
tempfile.write(chunk.b)
end
tempfile.rewind
tempfile
@@ -139,7 +146,7 @@ module GoogleDrive
end
response.read_body do |chunk|
yield chunk
yield chunk.b
end
end
end
+37 -6
ファイルの表示
@@ -21,10 +21,14 @@ class MaterialSyncRunner
result = Result.new(imported: 0, updated: 0, unchanged: 0,
suppressed: 0, failed: 0, errors: [])
candidates.each do |candidate|
next if candidate.blank?
if @source.source_kind == 'google_drive_path'
sync_google_drive_path!(result)
else
candidates.each do |candidate|
next if candidate.blank?
sync_candidate!(candidate, result)
sync_candidate!(candidate, result)
end
end
@source.update!(last_synced_at: Time.current)
@@ -43,8 +47,6 @@ class MaterialSyncRunner
case @source.source_kind
when 'uri'
[uri_candidate]
when 'google_drive_path'
google_drive_path_candidates
when 'google_drive_file'
[google_drive_file_candidate]
when 'legacy_drive_path'
@@ -104,12 +106,25 @@ class MaterialSyncRunner
def google_drive_path_candidates
folder_id = google_drive_folder_id
Enumerator.new do |entries|
drive_client.list_material_files_under_folder(folder_id).each do |entry|
drive_client.each_material_file_under_folder(folder_id).each do |entry|
entries << build_google_drive_candidate(entry)
end
end
end
def sync_google_drive_path! result
folder_id = google_drive_folder_id
scanned_count = 0
drive_client.each_material_file_under_folder(folder_id) do |entry|
scanned_count += 1
sync_candidate!(build_google_drive_candidate(entry), result)
log_google_drive_progress(folder_id, scanned_count, result) if progress_log_scan_count?(scanned_count)
end
log_google_drive_progress(folder_id, scanned_count, result, summary: true)
end
def google_drive_file_candidate
entry = drive_client.fetch_material_file(google_drive_file_id)
return nil unless entry
@@ -213,6 +228,22 @@ class MaterialSyncRunner
failed: result.failed))
end
def progress_log_scan_count? scanned_count
scanned_count == 1 || (scanned_count % 50).zero?
end
def log_google_drive_progress folder_id, scanned_count, result, summary: false
Rails.logger.info(
material_sync_log(folder_id:,
scanned_count:,
imported: result.imported,
updated: result.updated,
unchanged: result.unchanged,
suppressed: result.suppressed,
failed: result.failed,
progress: summary ? 'summary' : 'scan'))
end
def material_sync_log fields
{ material_sync_source_id: @source.id,
material_sync_source_name: @source.name }.merge(fields).to_json