Example #1
0
def invalidate_title(title):
    title = title.replace(" ", "_").replace(":", ".")
    invalidate_index(title)
    invalidate_counts(title)
    manager.run("ban",
                'obj.http.url ~ "/api/texts/{}"'.format(title),
                secret=secret)
    manager.run("ban",
                'obj.http.url ~ "/api/links/{}"'.format(title),
                secret=secret)
Example #2
0
def invalidate_ref(oref, lang=None, version=None, purge=False):
    """
    Called when 'ref' is changed.
    We aim to PURGE the main page, so that the results of any save will be immediately visible to the person editing.
    All other implications are handled with a blanket BAN.

    todo: Tune this so as not to ban when the version changed is not a displayed version
    """
    if not isinstance(oref, Ref):
        return

    if getattr(oref.index_node, u"depth",
               False) and len(oref.sections) >= oref.index_node.depth - 1:
        oref = oref.section_ref()

    if version:
        version = urllib.quote(version.replace(u" ", u"_").encode("utf-8"))
    if purge:
        # Purge this section level ref, so that immediate responses will return good results
        purge_url(u"{}/api/texts/{}".format(FRONT_END_URL, oref.url()))
        if version and lang:
            try:
                purge_url(u"{}/api/texts/{}/{}/{}".format(
                    FRONT_END_URL, oref.url(), lang, version))
            except Exception as e:
                logger.exception(e)
        # Hacky to add these
        purge_url(u"{}/api/texts/{}?commentary=1&sheets=1".format(
            FRONT_END_URL, oref.url()))
        purge_url(u"{}/api/texts/{}?sheets=1".format(FRONT_END_URL,
                                                     oref.url()))
        purge_url(u"{}/api/texts/{}?commentary=0".format(
            FRONT_END_URL, oref.url()))
        purge_url(u"{}/api/texts/{}?commentary=0&pad=0".format(
            FRONT_END_URL, oref.url()))
        if version and lang:
            try:
                purge_url(u"{}/api/texts/{}/{}/{}?commentary=0".format(
                    FRONT_END_URL, oref.url(), lang, version))
            except Exception as e:
                logger.exception(e)
        purge_url(u"{}/api/links/{}".format(FRONT_END_URL, oref.url()))
        purge_url(u"{}/api/links/{}?with_text=0".format(
            FRONT_END_URL, oref.url()))
        purge_url(u"{}/api/links/{}?with_text=1".format(
            FRONT_END_URL, oref.url()))

    # Ban anything underneath this section
    manager.run(u"ban",
                u'obj.http.url ~ "/api/texts/{}"'.format(url_regex(oref)),
                secret=secret)
    manager.run(u"ban",
                u'obj.http.url ~ "/api/links/{}"'.format(url_regex(oref)),
                secret=secret)
def invalidate_title(title):
    title = title.replace(" ", "_").replace(":", ".")

    # Parallel to sefaria.system.varnish.wrapper.invalidate_index()
    purge_url("{}/api/index/{}".format(FRONT_END_URL, title))
    purge_url("{}/api/v2/raw/index/{}".format(FRONT_END_URL, title))
    purge_url("{}/api/v2/index/{}".format(FRONT_END_URL, title))
    purge_url("{}/api/v2/index/{}?with_content_counts=1".format(FRONT_END_URL, title))

    # Parallel to sefaria.system.varnish.wrapper.invalidate_counts()
    purge_url("{}/api/preview/{}".format(FRONT_END_URL, title))
    purge_url("{}/api/counts/{}".format(FRONT_END_URL, title))
    purge_url("{}/api/v2/index/{}?with_content_counts=1".format(FRONT_END_URL, title))

    # Parallel to base of sefaria.system.varnish.wrapper.invalidate_title()
    manager.run("ban", 'obj.http.url ~ "/api/texts/{}"'.format(title), secret=secret)
    manager.run("ban", 'obj.http.url ~ "/api/links/{}"'.format(title), secret=secret)
Example #4
0
def invalidate_ref(oref, lang=None, version=None, purge=False):
    """
    Called when 'ref' is changed.
    We aim to PURGE the main page, so that the results of any save will be immediately visible to the person editing.
    All other implications are handled with a blanket BAN.

    todo: Tune this so as not to ban when the version changed is not a displayed version
    """
    if not isinstance(oref, Ref):
        return
    
    if getattr(oref.index_node, u"depth", False) and len(oref.sections) >= oref.index_node.depth - 1:
        oref = oref.section_ref()

    if version:
        version = urllib.quote(version.replace(u" ", u"_").encode("utf-8"))
    if purge:
        # Purge this section level ref, so that immediate responses will return good results
        purge_url(u"{}/api/texts/{}".format(FRONT_END_URL, oref.url()))
        if version and lang:
            try:
                purge_url(u"{}/api/texts/{}/{}/{}".format(FRONT_END_URL, oref.url(), lang, version))
            except Exception as e:
                logger.exception(e)
        # Hacky to add these
        purge_url(u"{}/api/texts/{}?commentary=1&sheets=1".format(FRONT_END_URL, oref.url()))
        purge_url(u"{}/api/texts/{}?sheets=1".format(FRONT_END_URL, oref.url()))
        purge_url(u"{}/api/texts/{}?commentary=0".format(FRONT_END_URL, oref.url()))
        purge_url(u"{}/api/texts/{}?commentary=0&pad=0".format(FRONT_END_URL, oref.url()))
        if version and lang:
            try:
                purge_url(u"{}/api/texts/{}/{}/{}?commentary=0".format(FRONT_END_URL, oref.url(), lang, version))
            except Exception as e:
                logger.exception(e)
        purge_url(u"{}/api/links/{}".format(FRONT_END_URL, oref.url()))
        purge_url(u"{}/api/links/{}?with_text=0".format(FRONT_END_URL, oref.url()))
        purge_url(u"{}/api/links/{}?with_text=1".format(FRONT_END_URL, oref.url()))

    # Ban anything underneath this section
    manager.run(u"ban", u'obj.http.url ~ "/api/texts/{}"'.format(url_regex(oref)), secret=secret)
    manager.run(u"ban", u'obj.http.url ~ "/api/links/{}"'.format(url_regex(oref)), secret=secret)
Example #5
0
def invalidate_title(title):
    title = title.replace(" ", "_").replace(":", ".")
    invalidate_index(title)
    invalidate_counts(title)
    manager.run("ban", 'obj.http.url ~ "/api/texts/{}"'.format(title), secret=secret)
    manager.run("ban", 'obj.http.url ~ "/api/links/{}"'.format(title), secret=secret)