Skip to content

Commit ff1b849

Browse files
committed
Merge branch 'main' into refactor/thumbnail-renderers
# Conflicts: # pyproject.toml # src/tagstudio/qt/previews/renderer.py
2 parents b68e63a + 88d0b47 commit ff1b849

File tree

16 files changed

+198
-19
lines changed

16 files changed

+198
-19
lines changed

docs/library-changes.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,12 @@ Migration from the legacy JSON format is provided via a walkthrough when opening
123123
| [v9.5.4](https://github.com/TagStudioDev/TagStudio/releases/tag/v9.5.4) | SQLite | `<Library Folder>`/.TagStudio/ts_library.sqlite |
124124

125125
- Applies repairs to the `tag_parents` table created in [version 100](#version-100), removing rows that reference tags that have been deleted.
126+
127+
#### Version 103
128+
129+
| Used From | Format | Location |
130+
| ----------------------------------------------------------------------- | ------ | ----------------------------------------------- |
131+
| [#1139](https://github.com/TagStudioDev/TagStudio/pull/1139) | SQLite | `<Library Folder>`/.TagStudio/ts_library.sqlite |
132+
133+
- Adds the `is_hidden` column to the `tags` table (default `0`). Used for excluding entries tagged with hidden tags from library searches.
134+
- Sets the `is_hidden` field on the built-in Archived tag to `1`, to match the Archived tag now being hidden by default.

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/package/default.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ python3Packages.buildPythonApplication {
7070
"\${qtWrapperArgs[@]}"
7171
];
7272

73-
pythonRemoveDeps = lib.optional (!withJXLSupport) [ "pillow_jxl" ];
73+
pythonRemoveDeps = lib.optional (!withJXLSupport) "pillow_jxl";
7474
pythonRelaxDeps = [
7575
"numpy"
7676
"pillow"
@@ -96,7 +96,6 @@ python3Packages.buildPythonApplication {
9696
numpy
9797
opencv-python
9898
pillow
99-
pillow-avif-plugin
10099
pillow-heif
101100
py7zr
102101
pydantic

nix/shell.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pkgs.mkShellNoCC {
8787
env = {
8888
QT_QPA_PLATFORM = "wayland;xcb";
8989

90-
UV_NO_SYNC = "1";
90+
UV_NO_SYNC = 1;
9191
UV_PYTHON_DOWNLOADS = "never";
9292
};
9393

@@ -111,7 +111,8 @@ pkgs.mkShellNoCC {
111111
fi
112112
113113
source "''${venv}"/bin/activate
114-
PYTHONPATH=${pythonPath}''${PYTHONPATH:+:}''${PYTHONPATH:-}
114+
PYTHONPATH=${pythonPath}''${PYTHONPATH:+:''${PYTHONPATH}}
115+
export PYTHONPATH
115116
116117
if [ ! -f "''${venv}"/pyproject.toml ] || ! diff --brief pyproject.toml "''${venv}"/pyproject.toml >/dev/null; then
117118
printf '%s\n' 'Installing dependencies, pyproject.toml changed...' >&2

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ dependencies = [
1818
"numpy~=2.2",
1919
"opencv_python~=4.11",
2020
"openexr~=3.4.3",
21-
"Pillow>=10.2,<=11",
2221
"pillow-avif-plugin~=1.5",
22+
"Pillow>=10.2,<12",
2323
"pillow-heif~=0.22",
2424
"pillow-jxl-plugin~=1.3",
2525
"py7zr==1.0.0",

src/tagstudio/core/library/alchemy/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
DB_VERSION_LEGACY_KEY: str = "DB_VERSION"
1212
DB_VERSION_CURRENT_KEY: str = "CURRENT"
1313
DB_VERSION_INITIAL_KEY: str = "INITIAL"
14-
DB_VERSION: int = 102
14+
DB_VERSION: int = 103
1515

1616
TAG_CHILDREN_QUERY = text("""
1717
WITH RECURSIVE ChildTags AS (

src/tagstudio/core/library/alchemy/db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def make_tables(engine: Engine) -> None:
5757
conn.execute(
5858
text(
5959
"INSERT INTO tags "
60-
"(id, name, color_namespace, color_slug, is_category) VALUES "
61-
f"({RESERVED_TAG_END}, 'temp', NULL, NULL, false)"
60+
"(id, name, color_namespace, color_slug, is_category, is_hidden) VALUES "
61+
f"({RESERVED_TAG_END}, 'temp', NULL, NULL, false, false)"
6262
)
6363
)
6464
conn.execute(text(f"DELETE FROM tags WHERE id = {RESERVED_TAG_END}"))

src/tagstudio/core/library/alchemy/enums.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class BrowsingState:
8282
ascending: bool = True
8383
random_seed: float = 0
8484

85+
show_hidden_entries: bool = False
86+
8587
query: str | None = None
8688

8789
# Abstract Syntax Tree Of the current Search Query
@@ -147,6 +149,9 @@ def with_sorting_direction(self, ascending: bool) -> "BrowsingState":
147149
def with_search_query(self, search_query: str) -> "BrowsingState":
148150
return replace(self, query=search_query)
149151

152+
def with_show_hidden_entries(self, show_hidden_entries: bool) -> "BrowsingState":
153+
return replace(self, show_hidden_entries=show_hidden_entries)
154+
150155

151156
class FieldTypeEnum(enum.Enum):
152157
TEXT_LINE = "Text Line"

src/tagstudio/core/library/alchemy/library.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def get_default_tags() -> tuple[Tag, ...]:
151151
name="Archived",
152152
aliases={TagAlias(name="Archive")},
153153
parent_tags={meta_tag},
154+
is_hidden=True,
154155
color_slug="red",
155156
color_namespace="tagstudio-standard",
156157
)
@@ -540,6 +541,8 @@ def open_sqlite_library(self, library_dir: Path, is_new: bool) -> LibraryStatus:
540541
self.__apply_db8_schema_changes(session)
541542
if loaded_db_version < 9:
542543
self.__apply_db9_schema_changes(session)
544+
if loaded_db_version < 103:
545+
self.__apply_db103_schema_changes(session)
543546
if loaded_db_version == 6:
544547
self.__apply_repairs_for_db6(session)
545548

@@ -551,6 +554,8 @@ def open_sqlite_library(self, library_dir: Path, is_new: bool) -> LibraryStatus:
551554
self.__apply_db100_parent_repairs(session)
552555
if loaded_db_version < 102:
553556
self.__apply_db102_repairs(session)
557+
if loaded_db_version < 103:
558+
self.__apply_db103_default_data(session)
554559

555560
# Convert file extension list to ts_ignore file, if a .ts_ignore file does not exist
556561
self.migrate_sql_to_ts_ignore(library_dir)
@@ -698,6 +703,36 @@ def __apply_db102_repairs(self, session: Session):
698703
session.commit()
699704
logger.info("[Library][Migration] Verified TagParent table data")
700705

706+
def __apply_db103_schema_changes(self, session: Session):
707+
"""Apply database schema changes introduced in DB_VERSION 103."""
708+
add_is_hidden_column = text(
709+
"ALTER TABLE tags ADD COLUMN is_hidden BOOLEAN NOT NULL DEFAULT 0"
710+
)
711+
try:
712+
session.execute(add_is_hidden_column)
713+
session.commit()
714+
logger.info("[Library][Migration] Added is_hidden column to tags table")
715+
except Exception as e:
716+
logger.error(
717+
"[Library][Migration] Could not create is_hidden column in tags table!",
718+
error=e,
719+
)
720+
session.rollback()
721+
722+
def __apply_db103_default_data(self, session: Session):
723+
"""Apply default data changes introduced in DB_VERSION 103."""
724+
try:
725+
session.query(Tag).filter(Tag.id == TAG_ARCHIVED).update({"is_hidden": True})
726+
session.commit()
727+
logger.info("[Library][Migration] Updated archived tag to be hidden")
728+
session.commit()
729+
except Exception as e:
730+
logger.error(
731+
"[Library][Migration] Could not update archived tag to be hidden!",
732+
error=e,
733+
)
734+
session.rollback()
735+
701736
def migrate_sql_to_ts_ignore(self, library_dir: Path):
702737
# Do not continue if existing '.ts_ignore' file is found
703738
if Path(library_dir / TS_FOLDER_NAME / IGNORE_NAME).exists():
@@ -1003,13 +1038,19 @@ def search_library(
10031038
else:
10041039
statement = select(Entry.id)
10051040

1006-
if search.ast:
1041+
ast = search.ast
1042+
1043+
if not search.show_hidden_entries:
1044+
statement = statement.where(~Entry.tags.any(Tag.is_hidden))
1045+
1046+
if ast:
10071047
start_time = time.time()
1008-
statement = statement.where(SQLBoolExpressionBuilder(self).visit(search.ast))
1048+
statement = statement.where(SQLBoolExpressionBuilder(self).visit(ast))
10091049
end_time = time.time()
10101050
logger.info(
10111051
f"SQL Expression Builder finished ({format_timespan(end_time - start_time)})"
10121052
)
1053+
10131054
statement = statement.distinct(Entry.id)
10141055

10151056
sort_on: ColumnExpressionArgument = Entry.id

src/tagstudio/core/library/alchemy/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class Tag(Base):
9797
color_slug: Mapped[str | None] = mapped_column()
9898
color: Mapped[TagColorGroup | None] = relationship(lazy="joined")
9999
is_category: Mapped[bool]
100+
is_hidden: Mapped[bool]
100101
icon: Mapped[str | None]
101102
aliases: Mapped[set[TagAlias]] = relationship(back_populates="tag")
102103
parent_tags: Mapped[set["Tag"]] = relationship(
@@ -138,6 +139,7 @@ def __init__(
138139
color_slug: str | None = None,
139140
disambiguation_id: int | None = None,
140141
is_category: bool = False,
142+
is_hidden: bool = False,
141143
):
142144
self.name = name
143145
self.aliases = aliases or set()
@@ -148,6 +150,7 @@ def __init__(
148150
self.shorthand = shorthand
149151
self.disambiguation_id = disambiguation_id
150152
self.is_category = is_category
153+
self.is_hidden = is_hidden
151154
self.id = id # pyright: ignore[reportAttributeAccessIssue]
152155
super().__init__()
153156

0 commit comments

Comments
 (0)