VietCat commited on
Commit
2c5219c
·
1 Parent(s): 3f6c63c

add data viewer

Browse files
Files changed (1) hide show
  1. app/supabase_db.py +17 -4
app/supabase_db.py CHANGED
@@ -197,14 +197,28 @@ class SupabaseClient:
197
  total_count = count_response.count if hasattr(count_response, 'count') else 'unknown'
198
  logger.info(f"[SUPABASE] Total records in table: {total_count}")
199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  all_chunks = []
201
- page_size = 500 # Giảm page size để test
202
  start = 0
203
  page_count = 0
204
 
205
  while True:
206
  page_count += 1
207
- # Sử dụng .range() với page size nhỏ hơn
208
  response = self.client.table('document_chunks').select('*').range(start, start + page_size - 1).execute()
209
 
210
  actual_count = len(response.data) if response.data else 0
@@ -216,14 +230,13 @@ class SupabaseClient:
216
 
217
  all_chunks.extend(response.data)
218
 
219
- # Nếu số records ít hơn page_size, đã hết
220
  if actual_count < page_size:
221
  logger.info(f"[SUPABASE] Last page with {actual_count} records")
222
  break
223
 
224
  start += page_size
225
 
226
- logger.info(f"[SUPABASE] Successfully fetched {len(all_chunks)} document chunks (expected: {total_count})")
227
  logger.info(f"[SUPABASE] Fetched {page_count} pages with page_size={page_size}")
228
  return all_chunks
229
 
 
197
  total_count = count_response.count if hasattr(count_response, 'count') else 'unknown'
198
  logger.info(f"[SUPABASE] Total records in table: {total_count}")
199
 
200
+ # Thử lấy tất cả với limit lớn
201
+ logger.info("[SUPABASE] Trying to fetch all records with large limit")
202
+ response = self.client.table('document_chunks').select('*').limit(10000).execute()
203
+
204
+ if response.data:
205
+ actual_count = len(response.data)
206
+ logger.info(f"[SUPABASE] Large limit fetched {actual_count} document chunks (expected: {total_count})")
207
+
208
+ if isinstance(total_count, int) and actual_count >= total_count:
209
+ logger.info("[SUPABASE] Successfully fetched all records")
210
+ return response.data
211
+ else:
212
+ logger.warning(f"[SUPABASE] Only got {actual_count}/{total_count} records, trying pagination")
213
+
214
+ # Fallback to pagination with very small page size
215
  all_chunks = []
216
+ page_size = 300 # Rất nhỏ để test
217
  start = 0
218
  page_count = 0
219
 
220
  while True:
221
  page_count += 1
 
222
  response = self.client.table('document_chunks').select('*').range(start, start + page_size - 1).execute()
223
 
224
  actual_count = len(response.data) if response.data else 0
 
230
 
231
  all_chunks.extend(response.data)
232
 
 
233
  if actual_count < page_size:
234
  logger.info(f"[SUPABASE] Last page with {actual_count} records")
235
  break
236
 
237
  start += page_size
238
 
239
+ logger.info(f"[SUPABASE] Pagination fetched {len(all_chunks)} document chunks (expected: {total_count})")
240
  logger.info(f"[SUPABASE] Fetched {page_count} pages with page_size={page_size}")
241
  return all_chunks
242