Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timehashes to nip 52 #1752

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

staab
Copy link
Member

@staab staab commented Feb 5, 2025

This does the same thing for timestamps as geohashes does for locations. There's likely a better way to accomplish the task, so feel suggestions on the code snippets and algorithm are welcome.

@fiatjaf
Copy link
Member

fiatjaf commented Feb 5, 2025

Beautiful, elegant solution.

@staab
Copy link
Member Author

staab commented Feb 5, 2025

Thinking through this more (thank you @arkin0x), there are degenerate scenarios in which long-duration events require many high-granularity hashes. This case can't be solved by only using lower-granularity hashes, because clients using high-granularity hashes in requests will no longer be able to find those events, and lower-granularity hashes force them to download and filter everything.

So I decided that the simplest thing to do is just pick a granularity and use it. As it happens one day is probably a pretty good balance for most use cases. Date-only events already have that information (and are timezone-agnostic anyway), so I only had to add the tag to datetime events.

@tyiu @arkin0x

@staab staab marked this pull request as ready for review February 5, 2025 23:40
@fiatjaf
Copy link
Member

fiatjaf commented Feb 6, 2025

Beautiful, elegant solution.

@mikedilger
Copy link
Contributor

So if you want all events happening this Friday, you can look them up with the "D" tag and it will include week-long events including Friday. Sounds good to me.

@staab
Copy link
Member Author

staab commented Feb 6, 2025

Flotilla now publishes and filters using the D tag

@tyiu
Copy link
Contributor

tyiu commented Feb 7, 2025

So if I wanted to get all the events for the next month, I would have to include ~30 D-tags in the subscription filter?

@1l0
Copy link

1l0 commented Feb 7, 2025

How about this

// Start timehashes
    ["T", "dy"],
    ["T", "dyj"],
    ["T", "dyju"],
    
// End timehashes
    ["D", "dy"],
    ["D", "dyj"],
    ["D", "dyju"],

@staab
Copy link
Member Author

staab commented Feb 7, 2025

So if I wanted to get all the events for the next month, I would have to include ~30 D-tags in the subscription filter?

Yes. Not that bad if you compare it to the authors field.

How about this

This isn't terrible, but it doesn't allow targeting hashes during but not at the end or start of the event. You'd still have to scan backwards and forwards to get a complete list of events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants