store: refactor access hash and session tables

* Move sessions to user_login metadata, as that data rarely changes after login.
* Merge user and channel access hashes. Those IDs don't conflict.
* Split usernames into a new table to allow better `ON CONFLICT` updates
  (when a username moves to another entity, we want the old row to be replaced).
  Usernames also don't need to be scoped to a login.
This commit is contained in:
Tulir Asokan
2024-08-22 16:21:24 +03:00
parent e611c87342
commit b25c09fc53
14 changed files with 129 additions and 195 deletions
+1 -3
View File
@@ -195,10 +195,8 @@ func (t *Transferer) WithPhoto(pc tg.PhotoClass) *ReadyTransferer {
// given user's photo as the location that will be downloaded by the
// [ReadyTransferer].
func (t *Transferer) WithUserPhoto(ctx context.Context, store *store.ScopedStore, user *tg.User, photoID int64) (*ReadyTransferer, error) {
if accessHash, found, err := store.GetUserAccessHash(ctx, user.GetID()); err != nil {
if accessHash, err := store.GetAccessHash(ctx, user.GetID()); err != nil {
return nil, fmt.Errorf("failed to get user access hash for %d: %w", user.GetID(), err)
} else if !found {
return nil, fmt.Errorf("user access hash not found for %d", user.GetID())
} else {
return &ReadyTransferer{
inner: t,