Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
Merge remote-tracking branch 'v7/main' into v7
joshistoasteeb00947c834
diff --cc invokeai/app/api/routers/session_queue.pyindex 30e0c2eaaa,cd2260d227..1b057d671e--- a/invokeai/app/api/routers/session_queue.py+++ b/invokeai/app/api/routers/session_queue.py@@@ -206,14 -140,19 +206,22 @@@ async def get_queue_item_idscurrent_user: CurrentUserOrDefault,queue_id: str = Path(description="The queue id to perform this operation on"),order_dir: SQLiteDirection = Query(default=SQLiteDirection.Descending, description="The order of sort"),+ origin_prefix: Optional[str] = Query(default=None, description="Only include queue items whose origin starts with this prefix"),) -> ItemIdsResult:- """Gets all queue item ids that match the given parameters. Non-admin users only see their own items."""+ """Gets all queue item ids that match the given parameters.++ IDs for every user's items are returned (item ids carry no sensitive data on their own).+ When the corresponding items are hydrated via get_queue_items_by_item_ids, those belonging+ to other users are redacted by sanitize_queue_item_for_user. This lets a non-admin see+ partially-redacted entries for other users' jobs in the queue list, while still revealing+ only timestamps and status for items they do not own.++ current_user is required so the endpoint stays behind authentication in multiuser mode.+ """try:- user_id = None if current_user.is_admin else current_user.user_id- return ApiDependencies.invoker.services.session_queue.get_queue_item_ids(queue_id=queue_id, order_dir=order_dir)+ return ApiDependencies.invoker.services.session_queue.get_queue_item_ids(- queue_id=queue_id, order_dir=order_dir, user_id=user_id, origin_prefix=origin_prefix++ queue_id=queue_id, order_dir=order_dir, origin_prefix=origin_prefix+ )except Exception as e:raise HTTPException(status_code=500, detail=f"Unexpected error while listing all queue item ids: {e}")diff --cc invokeai/app/services/session_queue/session_queue_base.pyindex 231352ea14,bb7971cf90..09b521d681--- a/invokeai/app/services/session_queue/session_queue_base.py+++ b/invokeai/app/services/session_queue/session_queue_base.py@@@ -78,9 -78,12 +78,13 @@@ class SessionQueueBase(ABC)queue_id: str,user_id: Optional[str] = None,acting_user_id: Optional[str] = None,+ origin_prefix: Optional[str] = None,) -> SessionQueueStatus:- """Gets the status of the queue. If user_id is provided, also includes user-specific counts.+ """Gets the status of the queue.++ Aggregate counts (pending/in_progress/.../total) are always global across all users.+ If user_id is provided, the requesting user's own counts are additionally returned in+ the user_pending/user_in_progress fields (left None otherwise).acting_user_id is independent of user_id and controls only current-item redaction:when set, the returned status omits item_id/session_id/batch_id unless thediff --cc invokeai/app/services/session_queue/session_queue_sqlite.pyindex 1b5fd3951e,c29ed9b003..71eba1eb48--- a/invokeai/app/services/session_queue/session_queue_sqlite.py+++ b/invokeai/app/services/session_queue/session_queue_sqlite.py@@@ -875,30 -858,39 +875,48 @@@ class SqliteSessionQueue(SessionQueueBaqueue_id: str,user_id: Optional[str] = None,acting_user_id: Optional[str] = None,+ origin_prefix: Optional[str] = None,) -> SessionQueueStatus:with self._db.transaction() as cursor:- # When user_id is provided (non-admin), only count that user's items- # Aggregate counts are always global (across all users). This lets a non-admin's- # badge show "own / total" — their share of the whole queue — and lets the queue- # list surface (redacted) entries belonging to other users.- cursor.execute(- """--sql++ # Aggregate counts are global across all users within the requested scope.+ query = """--sqlSELECT status, count(*)FROM session_queueWHERE queue_id = ?- GROUP BY status- """,- (queue_id,),- )+ """+ params: list[str] = [queue_id]+- if user_id is not None:- query += " AND user_id = ?"- params.append(user_id)-+ if origin_prefix is not None:+ query += " AND origin LIKE ?"+ params.append(f"{origin_prefix}%")++ query += " GROUP BY status"+ cursor.execute(query, params)counts_result = cast(list[sqlite3.Row], cursor.fetchall())+ # When user_id is provided, additionally compute that user's own counts so the+ # caller can render the per-user portion of the badge. These are returned in the+ # separate user_pending/user_in_progress fields and never replace the global counts.+ user_counts_result: list[sqlite3.Row] = []+ if user_id is not None:- cursor.execute(- """--sql++ user_query = """--sql+ SELECT status, count(*)+ FROM session_queue+ WHERE queue_id = ? AND user_id = ?++ """++ user_params = [queue_id, user_id]++++ if origin_prefix is not None:++ user_query += " AND origin LIKE ?"++ user_params.append(f"{origin_prefix}%")++++ user_query += """--sql+ GROUP BY status- """,- (queue_id, user_id),- )++ """++ cursor.execute(user_query, user_params)+ user_counts_result = cast(list[sqlite3.Row], cursor.fetchall())+- current_item = self.get_current(queue_id=queue_id)+ current_item = self.get_current(queue_id=queue_id, origin_prefix=origin_prefix)total = sum(row[1] or 0 for row in counts_result)counts: dict[str, int] = {row[0]: row[1] for row in counts_result}diff --cc invokeai/app/services/shared/sqlite_migrator/migrations/migration_32.pyindex 369fd3250d,5e06d634e7..edb60d4ac2--- a/invokeai/app/services/shared/sqlite_migrator/migrations/migration_32.py+++ b/invokeai/app/services/shared/sqlite_migrator/migrations/migration_32.py@@@ -17,21 -20,30 +20,29 @@@ from invokeai.app.services.shared.sqlitclass Migration32Callback:- """Migration to repair model_relationships foreign keys broken by migration 22."""+ """Migration to repair the broken foreign keys on the model_relationships table."""def __call__(self, cursor: sqlite3.Cursor) -> None:- self._rebuild_model_relationships(cursor)+ self._repair_model_relationships_fks(cursor)++ def _repair_model_relationships_fks(self, cursor: sqlite3.Cursor) -> None:+ cursor.execute("SELECT sql FROM sqlite_master WHERE type='table' AND name='model_relationships';")+ row = cursor.fetchone()+ if row is None:+ # Table does not exist (fresh db will create it correctly), nothing to repair.+ return- def _rebuild_model_relationships(self, cursor: sqlite3.Cursor) -> None:- cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='model_relationships';")- if cursor.fetchone() is None:+ existing_sql: str = row[0]+ if "models_old" not in existing_sql:+ # Foreign keys already point at the correct table, nothing to repair.return- # Rebuild the table with the correct foreign keys referencing models(id).cursor.execute("ALTER TABLE model_relationships RENAME TO model_relationships_old;")cursor.execute(- """--sql+ """+ -- many-to-many relationship table for modelsCREATE TABLE model_relationships (- -- model_key_1 and model_key_2 are the same as the id (primary key) in the models table+ -- model_key_1 and model_key_2 are the same as the key(primary key) in the models tablemodel_key_1 TEXT NOT NULL,model_key_2 TEXT NOT NULL,created_at TEXT DATETIME NOT NULL DEFAULT(STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),@@@ -42,13 -54,14 +53,14 @@@);""")- # Carry over relationships whose models still exist; anything else is- # unrecoverable garbage left behind by deletes that the broken foreign- # keys could not cascade.+- # Copy over the existing links, dropping any orphaned rows whose model keys no++ # Copy over existing links, dropping orphaned rows whose model keys no+ # longer exist -- these would violate the restored foreign keys.cursor.execute(- """--sql- INSERT OR IGNORE INTO model_relationships (model_key_1, model_key_2, created_at)- SELECT model_key_1, model_key_2, created_at FROM model_relationships_old+ """+ INSERT INTO model_relationships (model_key_1, model_key_2, created_at)+ SELECT model_key_1, model_key_2, created_at+ FROM model_relationships_oldWHERE model_key_1 IN (SELECT id FROM models)AND model_key_2 IN (SELECT id FROM models);"""