Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch carddb_optimization Excluding Merge-Ins
This is equivalent to a diff from 4efb66cf41 to 98551c9879
2022-07-08
| ||
17:46 | Optimized the card database size by only storing positive printing filters. Completes [4d9d5ad8f05730a5]. See [/wiki?name=branch/carddb_optimization&p] for benchmark details. check-in: c54adb5109 user: thomas tags: trunk | |
17:42 | Added changelog entry Closed-Leaf check-in: 98551c9879 user: thomas tags: carddb_optimization | |
17:30 | Further optimization during card data import: Instead of deleting excess entries in PrintingDisplayFilter individually, simply clear the whole table and re-populate it. check-in: 1dc70b4ec9 user: thomas tags: carddb_optimization | |
16:52 | Optimize the handling of printing filters. The database no longer stores the full cross product in the PrintingDisplayFilter table. Instead, only positive values (a filter applies to a printing) is stored. The negative case is now implied. This reduces the total table size from ~6.6 million to ~126 thousand entries. This reduces the database file size from ~230 MiB to 160 MiB. check-in: 0b50f651ab user: thomas tags: carddb_optimization | |
13:12 | Document.save_to_disk(): Added three logging lines. check-in: 4efb66cf41 user: thomas tags: trunk | |
2022-07-07
| ||
18:48 | Fixed an exception when a card with position greater than the number of document pages is deleted. Issue was introduced in [e7c36b589c0596a5]. check-in: 15b35e98c6 user: thomas tags: trunk | |
Changes to doc/changelog.md.
1 2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | - + + | # Changelog |
︙ |
Changes to mtg_proxy_printer/card_info_downloader.py.
︙ | |||
286 287 288 289 290 291 292 293 294 295 296 297 298 299 | 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | + + + + | for filter_name, filter_id in self.model.db.execute("SELECT filter_name, filter_id FROM DisplayFilters").fetchall()} set_wackiness_score_cache: typing.Dict[str, SetWackinessScore] = {} skipped_cards = 0 index = 0 face_ids: IntTuples = [] db: sqlite3.Connection = self.model.db # Will be re-populated while iterating over the card data. Axing the previous data is far cheaper than trying # to update it in-place by removing up to number-of-available-filters entries per each individual card, # just to make sure that rare un-banned cards are updated properly. db.execute("DELETE FROM PrintingDisplayFilter\n") for index, card in enumerate(card_data, start=1): if not self.should_run: logger.info(f"Aborting card import after {index} cards due to user request.") self.download_finished.emit() return index if card["object"] != "card": logger.warning(f"Non-card found in card data during import: {card}") |
︙ | |||
572 573 574 575 576 577 578 | 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | - - + - - - - + + | return result def _insert_card_filters( model: CardDatabase, printing_id: int, filter_data: typing.Dict[str, bool], printing_filter_ids: typing.Dict[str, int]): model.db.executemany( |
︙ |
Changes to mtg_proxy_printer/model/carddb.py.
︙ | |||
747 748 749 750 751 752 753 | 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | - + - - - - + + + + + + | filters_in_db: typing.Dict[str, bool] = { key: bool(value) for key, value in self.db.execute("SELECT filter_name, filter_active FROM DisplayFilters").fetchall() } filters_in_settings: typing.Dict[str, bool] = {key: section.getboolean(key) for key in section.keys()} return filters_in_settings != filters_in_db |
︙ |
Changes to mtg_proxy_printer/model/carddb.sql.
︙ | |||
10 11 12 13 14 15 16 | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | - + | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- You should have received a copy of the GNU General Public License -- along with this program. If not, see <http://www.gnu.org/licenses/>. |
︙ | |||
105 106 107 108 109 110 111 | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | - - - + + + | filter_active INTEGER NOT NULL CHECK (filter_active IN (TRUE, FALSE)) ); CREATE TABLE PrintingDisplayFilter ( -- Stores which filter applies to which printing. printing_id INTEGER NOT NULL REFERENCES Printing (printing_id) ON DELETE CASCADE, filter_id INTEGER NOT NULL REFERENCES DisplayFilters (filter_id) ON DELETE CASCADE, |
︙ | |||
154 155 156 157 158 159 160 | 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | - + - | JOIN PrintLanguage USING (language_id) WHERE Printing.is_hidden IS FALSE AND FaceName.is_hidden IS FALSE ; CREATE VIEW AllPrintings AS SELECT card_name, set_code, set_name, "language", collector_number, scryfall_id, highres_image, face_number, |
Changes to mtg_proxy_printer/model/carddb_migrations.py.
︙ | |||
562 563 564 565 566 567 568 569 570 571 572 573 574 575 | 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | JOIN MTGSet USING (set_id) JOIN CardFace USING (printing_id) JOIN FaceName USING (face_name_id) JOIN PrintLanguage USING (language_id)"""), ]: db.execute(statement) def _migrate_28_to_29(db: sqlite3.Connection): db.execute("DROP VIEW HiddenPrintings\n") db.execute(textwrap.dedent("""\ CREATE TABLE PrintingDisplayFilter2 ( -- Stores which filter applies to which printing. printing_id INTEGER NOT NULL REFERENCES Printing (printing_id) ON DELETE CASCADE, filter_id INTEGER NOT NULL REFERENCES DisplayFilters (filter_id) ON DELETE CASCADE, PRIMARY KEY (printing_id, filter_id) ) WITHOUT ROWID; """)) db.execute(textwrap.dedent("""\ INSERT INTO PrintingDisplayFilter2 (printing_id, filter_id) SELECT printing_id, filter_id FROM PrintingDisplayFilter WHERE filter_applies IS TRUE """)) db.execute("DROP TABLE PrintingDisplayFilter\n") db.execute("ALTER TABLE PrintingDisplayFilter2 RENAME TO PrintingDisplayFilter\n") db.execute(textwrap.dedent("""\ CREATE VIEW HiddenPrintingIDs AS SELECT printing_id FROM PrintingDisplayFilter JOIN DisplayFilters USING (filter_id) WHERE filter_active IS TRUE GROUP BY printing_id ; """)) db.execute("DROP VIEW AllPrintings\n") db.execute(textwrap.dedent("""\ CREATE VIEW AllPrintings AS SELECT card_name, set_code, set_name, "language", collector_number, scryfall_id, highres_image, face_number, is_front, is_oversized, png_image_uri, oracle_id, release_date, wackiness_score, Printing.is_hidden FROM Card JOIN Printing USING (card_id) JOIN MTGSet USING (set_id) JOIN CardFace USING (printing_id) JOIN FaceName USING (face_name_id) JOIN PrintLanguage USING (language_id) ; """)) MIGRATION_SCRIPTS: MigrationScriptListing = ( # First component of each tuple contains the source schema version, second contains the migration script function. # These MUST be ordered by source schema version, otherwise the migration logic breaks. In other words: APPEND only. (9, _migrate_9_to_10), (10, _migrate_10_to_11), (11, _migrate_11_to_12), |
︙ | |||
585 586 587 588 589 590 591 592 593 594 595 596 597 598 | 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | + | (21, _migrate_21_to_22), (22, _migrate_22_to_23), (23, _migrate_23_to_24), (24, _migrate_24_to_25), (25, _migrate_25_to_26), (26, _migrate_26_to_27), (27, _migrate_27_to_28), (28, _migrate_28_to_29), ) def migrate_card_database_location(): from mtg_proxy_printer.model.carddb import DEFAULT_DATABASE_LOCATION, OLD_DATABASE_LOCATION if DEFAULT_DATABASE_LOCATION.exists() and OLD_DATABASE_LOCATION.exists(): logger.warning(f"A card database at both the new location '{DEFAULT_DATABASE_LOCATION}' and the old location " |
︙ | |||
612 613 614 615 616 617 618 | 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 | - + - + - + - + - + - - - + + + + | schema version right before it is executed. Each migration script must upgrade to the next schema version. Functions that combine multiple version upgrades in one SQL script are not supported. :param db: card database, given as a plain sqlite3 database connection object :param migration_scripts: List of migration script functions to run, if applicable. Defaults to a built-in list of migration scripts. Should only be passed explicitly for testing purposes. """ |
Changes to tests/helpers.py.
︙ | |||
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | + + + + + + + + - + - - - | dw.populate_database(data) @functools.lru_cache() def load_json(name: str) -> mtg_proxy_printer.card_info_downloader.JSONType: return json.loads(pkg_resources.resource_string("tests.json_samples", f"{name}.json").decode("utf-8")) def load_multiple_json_cards( json_files_or_names: typing.List[typing.Union[str, mtg_proxy_printer.card_info_downloader.JSONType]]): return [ load_json(json_file_or_name) if isinstance(json_file_or_name, str) else json_file_or_name for json_file_or_name in json_files_or_names ] def fill_card_database_with_json_cards( qtbot: QtBot, card_db: mtg_proxy_printer.model.carddb.CardDatabase, json_files_or_names: typing.List[typing.Union[str, mtg_proxy_printer.card_info_downloader.JSONType]], filter_settings: typing.Dict[str, str] = None) -> mtg_proxy_printer.model.carddb.CardDatabase: section = mtg_proxy_printer.settings.settings["card-filter"] settings_to_use = {filter_name: "False" for filter_name in section.keys()} if filter_settings: settings_to_use.update(filter_settings) |
︙ |
Changes to tests/test_card_info_downloader.py.
︙ | |||
10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | + | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import dataclasses import sqlite3 import typing import unittest.mock from hamcrest import * import pytest from mtg_proxy_printer.card_info_downloader import SetWackinessScore |
︙ | |||
183 184 185 186 187 188 189 | 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | - + | """Checks png_image_uri, is_front, face_number""" assert_that( data := card_db.db.execute(f"SELECT png_image_uri, is_front, face_number FROM {relation_name}").fetchall(), contains_inanyorder(*test_case.db_card_face()), f"CardFace relation contains unexpected data: {data}") |
︙ | |||
207 208 209 210 211 212 213 | 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | - + | """ _assert_printing_contains(card_db, test_case, is_hidden=False) _assert_card_face_contains(card_db, test_case) _assert_face_name_contains(card_db, test_case) _assert_set_contains(card_db, test_case) _assert_card_contains(card_db, test_case) _assert_print_language_contains(card_db, test_case) |
︙ | |||
441 442 443 444 445 446 447 | 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | "en", "28", "650722b4-d72b-4745-a1a5-00a34836282b", "7e6b9b59-cd68-4e3c-827b-38833c92d6eb", True, ) filter_name = "hide-oversized-cards" # Pass 1: Populate the database and exclude the card. The card should not be visible fill_card_database_with_json_card(qtbot, card_db, test_case.json_name, {filter_name: "True"}) assert_hidden_import(card_db, test_case) # Pass 2: Re-Populate the database, but include the card now. |
︙ |