Changeset - f0a5116429a4
[Not reviewed]
0 1 0
Brett Smith - 3 years ago 2021-03-12 19:58:14
brettcsmith@brettcsmith.org
query: Add ContextMeta function.

Deduplicate metadata lookup code.
1 file changed with 11 insertions and 10 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/query.py
Show inline comments
...
 
@@ -110,3 +110,2 @@ from .. import rtutil
 
PROGNAME = 'query-report'
 
SENTINEL = object()
 
logger = logging.getLogger('conservancy_beancount.reports.query')
...
 
@@ -156,2 +155,10 @@ class PostingContext:
 

	
 
def ContextMeta(context: PostingContext) -> data.PostingMeta:
 
    """Build a read-only PostingMeta object from the query context"""
 
    # We use sys.maxsize as the index because using a constant is fast, and
 
    # that helps keep the object read-only: if it ever tries to manipulate
 
    # the transaction, it'll get an IndexError.
 
    return data.PostingMeta(context.entry, sys.maxsize, context.posting).detached()
 

	
 

	
 
class MetaDocs(bc_query_env.AnyMeta):
...
 
@@ -268,12 +275,6 @@ class RTTicket(bc_query_compile.EvalFunction):
 
        meta_key = self._meta_key(meta_key)
 
        if context.posting.meta is None:
 
            meta_value: Any = SENTINEL
 
        else:
 
            meta_value = context.posting.meta.get(meta_key, SENTINEL)
 
        if meta_value is SENTINEL:
 
            meta_value = context.entry.meta.get(meta_key)
 
        if not isinstance(meta_value, str) or limit < 1:
 
            meta_value = ''
 
        if limit < 1:
 
            return set()
 
        ticket_ids: Set[str] = set()
 
        for link_s in meta_value.split():
 
        for link_s in ContextMeta(context).report_links(meta_key):
 
            rt_id = rtutil.RT.parse(link_s)
0 comments (0 inline, 0 general)