Show More
@@ -429,11 +429,6 b' def repo2db_mapper(initial_repo_list, re' | |||
|
429 | 429 | raise Exception('Missing administrative account!') |
|
430 | 430 | added = [] |
|
431 | 431 | |
|
432 | # # clear cache keys | |
|
433 | # log.debug("Clearing cache keys now...") | |
|
434 | # CacheInvalidation.clear_cache() | |
|
435 | # sa.commit() | |
|
436 | ||
|
437 | 432 | ##creation defaults |
|
438 | 433 | defs = RhodeCodeSetting.get_default_repo_settings(strip_prefix=True) |
|
439 | 434 | enable_statistics = defs.get('repo_enable_statistics') |
@@ -474,10 +469,9 b' def repo2db_mapper(initial_repo_list, re' | |||
|
474 | 469 | ScmModel().install_git_hook(db_repo.scm_instance) |
|
475 | 470 | # during starting install all cache keys for all repositories in the |
|
476 | 471 | # system, this will register all repos and multiple instances |
|
477 |
|
|
|
472 | cache_key = CacheInvalidation._get_cache_key(name) | |
|
473 | log.debug("Creating invalidation cache key for %s: %s", name, cache_key) | |
|
478 | 474 | CacheInvalidation.invalidate(name) |
|
479 | log.debug("Creating a cache key for %s, instance_id %s" | |
|
480 | % (name, _prefix or 'unknown')) | |
|
481 | 475 | |
|
482 | 476 | sa.commit() |
|
483 | 477 | removed = [] |
@@ -1630,9 +1630,13 b' class CacheInvalidation(Base, BaseModel)' | |||
|
1630 | 1630 | {'extend_existing': True, 'mysql_engine': 'InnoDB', |
|
1631 | 1631 | 'mysql_charset': 'utf8'}, |
|
1632 | 1632 | ) |
|
1633 | # cache_id, not used | |
|
1633 | 1634 | cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
1635 | # cache_key as created by _get_cache_key | |
|
1634 | 1636 | cache_key = Column("cache_key", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
1637 | # cache_args is usually a repo_name, possibly with _README/_RSS/_ATOM suffix | |
|
1635 | 1638 | cache_args = Column("cache_args", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
1639 | # instance sets cache_active True when it is caching, other instances set cache_active to False to invalidate | |
|
1636 | 1640 | cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False) |
|
1637 | 1641 | |
|
1638 | 1642 | def __init__(self, cache_key, cache_args=''): |
@@ -1644,43 +1648,27 b' class CacheInvalidation(Base, BaseModel)' | |||
|
1644 | 1648 | return u"<%s('%s:%s')>" % (self.__class__.__name__, |
|
1645 | 1649 | self.cache_id, self.cache_key) |
|
1646 | 1650 | |
|
1647 | @property | |
|
1648 | def prefix(self): | |
|
1651 | def get_prefix(self): | |
|
1652 | """ | |
|
1653 | Guess prefix that might have been used in _get_cache_key to generate self.cache_key . | |
|
1654 | Only used for informational purposes in repo_edit.html . | |
|
1655 | """ | |
|
1649 | 1656 | _split = self.cache_key.split(self.cache_args, 1) |
|
1650 |
if |
|
|
1657 | if len(_split) == 2: | |
|
1651 | 1658 | return _split[0] |
|
1652 | 1659 | return '' |
|
1653 | 1660 | |
|
1654 | 1661 | @classmethod |
|
1655 |
def |
|
|
1656 | cls.query().delete() | |
|
1657 | ||
|
1658 | @classmethod | |
|
1659 | def _get_key(cls, key): | |
|
1662 | def _get_cache_key(cls, key): | |
|
1660 | 1663 | """ |
|
1661 |
Wrapper for generating a |
|
|
1662 | ||
|
1663 | :param key: | |
|
1664 | Wrapper for generating a unique cache key for this instance and "key". | |
|
1664 | 1665 | """ |
|
1665 | 1666 | import rhodecode |
|
1666 | prefix = '' | |
|
1667 | org_key = key | |
|
1668 | iid = rhodecode.CONFIG.get('instance_id') | |
|
1669 | if iid: | |
|
1670 | prefix = iid | |
|
1671 | ||
|
1672 | return "%s%s" % (prefix, key), prefix, org_key | |
|
1667 | prefix = rhodecode.CONFIG.get('instance_id', '') | |
|
1668 | return "%s%s" % (prefix, key) | |
|
1673 | 1669 | |
|
1674 | 1670 | @classmethod |
|
1675 | def get_by_key(cls, key): | |
|
1676 | return cls.query().filter(cls.cache_key == key).scalar() | |
|
1677 | ||
|
1678 | @classmethod | |
|
1679 | def get_by_repo_name(cls, repo_name): | |
|
1680 | return cls.query().filter(cls.cache_args == repo_name).all() | |
|
1681 | ||
|
1682 | @classmethod | |
|
1683 | def _get_or_create_key(cls, key, repo_name, commit=True): | |
|
1671 | def _get_or_create_inv_obj(cls, key, repo_name, commit=True): | |
|
1684 | 1672 | inv_obj = Session().query(cls).filter(cls.cache_key == key).scalar() |
|
1685 | 1673 | if not inv_obj: |
|
1686 | 1674 | try: |
@@ -1707,9 +1695,8 b' class CacheInvalidation(Base, BaseModel)' | |||
|
1707 | 1695 | repo_name = remove_suffix(repo_name, '_RSS') |
|
1708 | 1696 | repo_name = remove_suffix(repo_name, '_ATOM') |
|
1709 | 1697 | |
|
1710 | # adds instance prefix | |
|
1711 | key, _prefix, _org_key = cls._get_key(key) | |
|
1712 | inv = cls._get_or_create_key(key, repo_name) | |
|
1698 | cache_key = cls._get_cache_key(key) | |
|
1699 | inv = cls._get_or_create_inv_obj(cache_key, repo_name) | |
|
1713 | 1700 | |
|
1714 | 1701 | if inv and inv.cache_active is False: |
|
1715 | 1702 | return inv |
@@ -1724,9 +1711,11 b' class CacheInvalidation(Base, BaseModel)' | |||
|
1724 | 1711 | """ |
|
1725 | 1712 | invalidated_keys = [] |
|
1726 | 1713 | if key: |
|
1727 | key, _prefix, _org_key = cls._get_key(key) | |
|
1728 | inv_objs = Session().query(cls).filter(cls.cache_key == key).all() | |
|
1729 | elif repo_name: | |
|
1714 | assert not repo_name | |
|
1715 | cache_key = cls._get_cache_key(key) | |
|
1716 | inv_objs = Session().query(cls).filter(cls.cache_key == cache_key).all() | |
|
1717 | else: | |
|
1718 | assert repo_name | |
|
1730 | 1719 | inv_objs = Session().query(cls).filter(cls.cache_args == repo_name).all() |
|
1731 | 1720 | |
|
1732 | 1721 | try: |
@@ -1749,7 +1738,7 b' class CacheInvalidation(Base, BaseModel)' | |||
|
1749 | 1738 | |
|
1750 | 1739 | :param key: |
|
1751 | 1740 | """ |
|
1752 |
inv_obj = cls. |
|
|
1741 | inv_obj = cls.query().filter(cls.cache_key == key).scalar() | |
|
1753 | 1742 | inv_obj.cache_active = True |
|
1754 | 1743 | Session().add(inv_obj) |
|
1755 | 1744 | Session().commit() |
@@ -1760,28 +1749,26 b' class CacheInvalidation(Base, BaseModel)' | |||
|
1760 | 1749 | class cachemapdict(dict): |
|
1761 | 1750 | |
|
1762 | 1751 | def __init__(self, *args, **kwargs): |
|
1763 |
fixkey = kwargs. |
|
|
1764 | if fixkey: | |
|
1765 | del kwargs['fixkey'] | |
|
1766 | self.fixkey = fixkey | |
|
1752 | self.fixkey = kwargs.pop('fixkey', False) | |
|
1767 | 1753 | super(cachemapdict, self).__init__(*args, **kwargs) |
|
1768 | 1754 | |
|
1769 | 1755 | def __getattr__(self, name): |
|
1770 | key = name | |
|
1756 | cache_key = name | |
|
1771 | 1757 | if self.fixkey: |
|
1772 |
|
|
|
1773 | if key in self.__dict__: | |
|
1774 | return self.__dict__[key] | |
|
1758 | cache_key = cls._get_cache_key(name) | |
|
1759 | if cache_key in self.__dict__: | |
|
1760 | return self.__dict__[cache_key] | |
|
1775 | 1761 | else: |
|
1776 | return self[key] | |
|
1762 | return self[cache_key] | |
|
1777 | 1763 | |
|
1778 |
def __getitem__(self, |
|
|
1764 | def __getitem__(self, name): | |
|
1765 | cache_key = name | |
|
1779 | 1766 | if self.fixkey: |
|
1780 |
|
|
|
1767 | cache_key = cls._get_cache_key(name) | |
|
1781 | 1768 | try: |
|
1782 | return super(cachemapdict, self).__getitem__(key) | |
|
1769 | return super(cachemapdict, self).__getitem__(cache_key) | |
|
1783 | 1770 | except KeyError: |
|
1784 | return | |
|
1771 | return None | |
|
1785 | 1772 | |
|
1786 | 1773 | cache_map = cachemapdict(fixkey=True) |
|
1787 | 1774 | for obj in cls.query().all(): |
General Comments 0
You need to be logged in to leave comments.
Login now