home / github

Menu
  • GraphQL API

github

Custom SQL query returning 9 rows (hide)

Query parameters

This data as json, CSV

html_urlissue_urlidnode_idusercreated_atupdated_atauthor_associationbodyreactionsissueperformed_via_github_app
https://github.com/simonw/datasette/issues/647#issuecomment-803673225 https://api.github.com/repos/simonw/datasette/issues/647 803673225 MDEyOklzc3VlQ29tbWVudDgwMzY3MzIyNQ== 9599 2021-03-21T22:44:19Z 2021-03-21T22:44:19Z OWNER Now that I'm looking at refactoring how views work in #878 it's clear that the gnarliest, most convoluted code I need to deal with relates to this old feature. I'm going to remove it entirely. Any performance enhancement or provides can be achieved just as well by using regular URLs and a caching proxy. I may provide a 404 handling plugin that attempts to rewrite old URLs that used this mechanism, but I won't do any more than that. {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 531755959  
https://github.com/simonw/datasette/issues/647#issuecomment-1061226942 https://api.github.com/repos/simonw/datasette/issues/647 1061226942 IC_kwDOBm6k_c4_QQm- 9599 2022-03-07T23:00:06Z 2022-03-07T23:00:06Z OWNER This needs to take into account the changes made here: - #1439 In the new encoding scheme, `-` has a special meaning in a table name: https://docs.datasette.io/en/latest/internals.html#dash-encoding I think `~` is the right character to use to separate a database name from its hash. `~` should be a URL safe character according to Python's implementation of percent-encoding, see comment here: https://github.com/simonw/datasette/blob/c5791156d92615f25696ba93dae5bb2dcc192c98/datasette/utils/__init__.py#L1146-L1152 So the plugin could check for `dbname~hash` and react based on that. {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 531755959  
https://github.com/simonw/datasette/issues/647#issuecomment-1061267615 https://api.github.com/repos/simonw/datasette/issues/647 1061267615 IC_kwDOBm6k_c4_Qaif 9599 2022-03-08T00:05:43Z 2022-03-08T00:05:43Z OWNER Built a prototype of that plugin: ```python from datasette import hookimpl from functools import wraps @hookimpl def asgi_wrapper(datasette): def wrap_with_hashed_urls(app): @wraps(app) async def hashed_urls(scope, receive, send): # Only triggers on pages with a path not starting in /-/ # and where the first page component matches a database name if scope.get("type") != "http": await app(scope, receive, send) return path = scope["path"].lstrip("/") if not path or path.startswith("-/"): await app(scope, receive, send) return potential_database = path.split("/")[0] # It may or may not be already dbname~hash if "~" in potential_database: db_name, hash = potential_database.split("~", 1) else: db_name = potential_database hash = "" # Is db_name a database we have a hash for? try: db = datasette.get_database(db_name) except KeyError: await app(scope, receive, send) return if db.hash is not None: # TODO: make sure db.hash is documented if db.hash[:7] != hash: # Send a redirect path_bits = path.split("/") new_path = "/" + "/".join(["{}-{}".format(db_name, db.hash[:7])] + path_bits[1:]) if scope.get("query_string"): new_path += "?" + scope["query_string"].decode("latin-1") await send({ "type": "http.response.start", "status": 302, "headers": [ [b"location", new_path.encode("latin1")] ], }) await send({"type": "http.response.b… {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 531755959  
https://github.com/simonw/datasette/issues/647#issuecomment-1061272544 https://api.github.com/repos/simonw/datasette/issues/647 1061272544 IC_kwDOBm6k_c4_Qbvg 9599 2022-03-08T00:14:42Z 2022-03-08T00:14:42Z OWNER Maybe the plugin should interfere with `datasette.databases` on startup and change the registered name for each one? {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 531755959  
https://github.com/simonw/datasette/issues/647#issuecomment-1061276399 https://api.github.com/repos/simonw/datasette/issues/647 1061276399 IC_kwDOBm6k_c4_Qcrv 9599 2022-03-08T00:21:47Z 2022-03-08T00:21:47Z OWNER This seems to do the job: ```python @hookimpl def startup(datasette): for name, database in datasette.databases.items(): if database.hash: new_name = "{}_{}".format(name, database.hash[:7]) del datasette.databases[name] datasette.databases[new_name] = database ``` Would have to teach the rest of the plugin to split on `_` and to only redirect if the user seems to be hitting the URL for an old hash after which Datasette has been restarted with an updated database. {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 531755959  
https://github.com/simonw/datasette/issues/647#issuecomment-1061276646 https://api.github.com/repos/simonw/datasette/issues/647 1061276646 IC_kwDOBm6k_c4_Qcvm 9599 2022-03-08T00:22:11Z 2022-03-08T00:22:11Z OWNER I'm now convinced this is feasible enough that it's worth doing in time for Datasette 1.0. {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 531755959  
https://github.com/simonw/datasette/issues/647#issuecomment-1061282743 https://api.github.com/repos/simonw/datasette/issues/647 1061282743 IC_kwDOBm6k_c4_QeO3 9599 2022-03-08T00:32:34Z 2022-03-08T00:32:47Z OWNER It would be neat if the plugin could spot old-style hyphen hash URLs (maybe on 404) and redirect those too. {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 531755959  
https://github.com/simonw/datasette/issues/647#issuecomment-1068539404 https://api.github.com/repos/simonw/datasette/issues/647 1068539404 IC_kwDOBm6k_c4_sJ4M 9599 2022-03-15T22:49:01Z 2022-03-15T22:49:01Z OWNER I shipped the first version of this: https://github.com/simonw/datasette-hashed-urls Next step: test it with a live demo: - https://github.com/simonw/datasette-hashed-urls/issues/2 {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 531755959  
https://github.com/simonw/datasette/issues/647#issuecomment-1068552696 https://api.github.com/repos/simonw/datasette/issues/647 1068552696 IC_kwDOBm6k_c4_sNH4 9599 2022-03-15T23:13:06Z 2022-03-15T23:13:06Z OWNER The plugin works. I'm going to implement one last feature for it: - https://github.com/simonw/datasette-hashed-urls/issues/3 Then I can remove hashed URL mode in a separate issue. {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} 531755959  
Powered by Datasette · Queries took 1.589ms · About: simonw/datasette-graphql