Commits

Kirill Simonov committed 53a3f96

Added addon `tweak.autolimit`.

The addon adds clause `LIMIT 10000` to every `SELECT` statement.

  • Participants
  • Parent commits 2ce6d93

Comments (0)

Files changed (4)

         'engine.mssql = htsql_mssql.export:ENGINE_MSSQL',
         'tweak.pgsql.timeout'
             ' = htsql_tweak.pgsql_timeout.export:TWEAK_PGSQL_TIMEOUT',
+        'tweak.autolimit = htsql_tweak.autolimit.export:TWEAK_AUTOLIMIT',
     ],
 }
 INSTALL_REQUIRES = [

src/htsql_tweak/autolimit/__init__.py

+#
+# Copyright (c) 2006-2011, Prometheus Research, LLC
+# Authors: Clark C. Evans <cce@clarkevans.com>,
+#          Kirill Simonov <xi@resolvent.net>
+#
+
+

src/htsql_tweak/autolimit/encode.py

+#
+# Copyright (c) 2006-2011, Prometheus Research, LLC
+# Authors: Clark C. Evans <cce@clarkevans.com>,
+#          Kirill Simonov <xi@resolvent.net>
+#
+
+
+from htsql.tr.encode import EncodeSegment
+from htsql.tr.code import OrderedSpace
+
+
+class AutolimitEncodeSegment(EncodeSegment):
+
+    default_limit = 10000
+
+    def __call__(self):
+        code = super(AutolimitEncodeSegment, self).__call__()
+        space = code.space
+        while isinstance(space, OrderedSpace):
+            if space.limit is not None and space.limit < self.default_limit:
+                return code
+            space = space.base
+        space = OrderedSpace(code.space, [], self.default_limit, None,
+                             code.binding)
+        return code.clone(space=space)
+
+

src/htsql_tweak/autolimit/export.py

+#
+# Copyright (c) 2006-2011, Prometheus Research, LLC
+# Authors: Clark C. Evans <cce@clarkevans.com>,
+#          Kirill Simonov <xi@resolvent.net>
+#
+
+
+from htsql.util import autoimport
+from htsql.addon import Addon
+
+
+autoimport('htsql_tweak.autolimit')
+
+
+class TWEAK_AUTOLIMIT(Addon):
+    pass
+
+