Arslan1997 commited on
Commit
fd0c922
·
1 Parent(s): 94f4eb8

LETS GOOOOOOOOOOOOOOOOOOOOOOOOO

Browse files
backend/app/pipeline/ingest.py CHANGED
@@ -575,12 +575,10 @@ def store_entries(
575
  return indexed, skipped, changed
576
 
577
 
578
- # Every plan reads the whole archive (up to this ceiling). Posts past the plan's indexed_posts are stored as locked:
579
- # listed with their title and text, but with no corpus file, so chat, notebooks and generation never see them.
580
- # Upgrading re-syncs and unlocks them without asking the writer to reconnect anything.
581
- ARCHIVE_SCAN_CAP = 5000
582
- # Sites without a feed are crawled page by page (Firecrawl scrapes when configured), so the ceiling is lower.
583
- SITE_SCAN_CAP = 500
584
 
585
 
586
  def _newest_first(entries: list[FeedEntry]) -> list[FeedEntry]:
@@ -623,12 +621,12 @@ def store_locked(db: Session, source: Source, entries: list[FeedEntry]) -> tuple
623
  def ingest_source(db: Session, source: Source, job: Job, max_posts: int) -> dict:
624
  source.sync_status = "syncing"
625
  update_job(db, job, status="running", progress=0.02, message="Contacting your feed")
626
- fetch_limit = ARCHIVE_SCAN_CAP
627
 
628
  if source.feed_url.startswith(SITE_PREFIX):
629
  update_job(db, job, message="Mapping your site")
630
  entries = crawl_site(
631
- source.feed_url.removeprefix(SITE_PREFIX), max(SITE_SCAN_CAP, max_posts),
632
  on_found=lambda n: update_job(db, job, progress=0.05, message=f"Found {n} pages, reading them"),
633
  on_post=lambda done, total: update_job(db, job, progress=0.05 + 0.05 * done / total,
634
  message=f"Read {done} of {total} pages"),
 
575
  return indexed, skipped, changed
576
 
577
 
578
+ # A sync reads up to SCAN_CAP posts (or the plan's own limit, if higher). Posts past the plan's indexed_posts are
579
+ # stored as locked: listed with their title and text, but with no corpus file, so chat, notebooks and generation
580
+ # never see them. Upgrading re-syncs and unlocks them without asking the writer to reconnect anything.
581
+ SCAN_CAP = 200
 
 
582
 
583
 
584
  def _newest_first(entries: list[FeedEntry]) -> list[FeedEntry]:
 
621
  def ingest_source(db: Session, source: Source, job: Job, max_posts: int) -> dict:
622
  source.sync_status = "syncing"
623
  update_job(db, job, status="running", progress=0.02, message="Contacting your feed")
624
+ fetch_limit = max(SCAN_CAP, max_posts)
625
 
626
  if source.feed_url.startswith(SITE_PREFIX):
627
  update_job(db, job, message="Mapping your site")
628
  entries = crawl_site(
629
+ source.feed_url.removeprefix(SITE_PREFIX), fetch_limit,
630
  on_found=lambda n: update_job(db, job, progress=0.05, message=f"Found {n} pages, reading them"),
631
  on_post=lambda done, total: update_job(db, job, progress=0.05 + 0.05 * done / total,
632
  message=f"Read {done} of {total} pages"),
backend/app/services/billing.py CHANGED
@@ -146,6 +146,8 @@ def apply_subscription(db: Session, workspace_id, *, plan: str, status: str, pro
146
  if plan not in PLANS:
147
  raise ValueError(f"Unknown plan {plan}")
148
  sub = db.query(Subscription).filter_by(workspace_id=workspace_id).one_or_none()
 
 
149
  if not sub:
150
  sub = Subscription(workspace_id=workspace_id)
151
  db.add(sub)
@@ -154,9 +156,23 @@ def apply_subscription(db: Session, workspace_id, *, plan: str, status: str, pro
154
  sub.provider_subscription_id = subscription_id or sub.provider_subscription_id
155
  sub.current_period_end = current_period_end
156
  db.commit()
 
 
157
  return sub
158
 
159
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  def return_urls() -> tuple[str, str]:
161
  """(success_url, cancel_url) for the hosted checkout page."""
162
  base = settings.frontend_url.rstrip("/")
 
146
  if plan not in PLANS:
147
  raise ValueError(f"Unknown plan {plan}")
148
  sub = db.query(Subscription).filter_by(workspace_id=workspace_id).one_or_none()
149
+ workspace = db.get(Workspace, workspace_id)
150
+ before = effective_plan(db, workspace).indexed_posts if workspace else None
151
  if not sub:
152
  sub = Subscription(workspace_id=workspace_id)
153
  db.add(sub)
 
156
  sub.provider_subscription_id = subscription_id or sub.provider_subscription_id
157
  sub.current_period_end = current_period_end
158
  db.commit()
159
+ if workspace and effective_plan(db, workspace).indexed_posts != before:
160
+ resync_sources(db, workspace_id)
161
  return sub
162
 
163
 
164
+ def resync_sources(db: Session, workspace_id) -> None:
165
+ """The post limit changed: re-sync every feed so locked posts unlock on upgrade (or re-lock on downgrade)."""
166
+ from app.pipeline.ingest import IMPORTS_FEED
167
+ from app.services.jobs import create_job
168
+
169
+ for source in db.scalars(select(Source).where(Source.workspace_id == workspace_id,
170
+ Source.feed_url != IMPORTS_FEED)):
171
+ source.sync_status = "pending"
172
+ create_job(db, workspace_id, "ingest", {"source_id": str(source.id)})
173
+ db.commit()
174
+
175
+
176
  def return_urls() -> tuple[str, str]:
177
  """(success_url, cancel_url) for the hosted checkout page."""
178
  base = settings.frontend_url.rstrip("/")