mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
Rehuffle where things are in the internal package (#1122)
renamed: internal/eventcontent.go -> internal/eventutil/eventcontent.go renamed: internal/events.go -> internal/eventutil/events.go renamed: internal/types.go -> internal/eventutil/types.go renamed: internal/http/http.go -> internal/httputil/http.go renamed: internal/httpapi.go -> internal/httputil/httpapi.go renamed: internal/httpapi_test.go -> internal/httputil/httpapi_test.go renamed: internal/httpapis/paths.go -> internal/httputil/paths.go renamed: internal/routing.go -> internal/httputil/routing.go renamed: internal/basecomponent/base.go -> internal/setup/base.go renamed: internal/basecomponent/flags.go -> internal/setup/flags.go renamed: internal/partition_offset_table.go -> internal/sqlutil/partition_offset_table.go renamed: internal/postgres.go -> internal/sqlutil/postgres.go renamed: internal/postgres_wasm.go -> internal/sqlutil/postgres_wasm.go renamed: internal/sql.go -> internal/sqlutil/sql.go
This commit is contained in:
parent
4675e1ddb6
commit
ecd7accbad
159 changed files with 784 additions and 693 deletions
|
@ -21,7 +21,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/roomserver/state"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage"
|
||||
|
@ -177,7 +177,7 @@ func (r *RoomserverInternalAPI) processInviteEvent(
|
|||
}
|
||||
succeeded := false
|
||||
defer func() {
|
||||
txerr := internal.EndTransaction(updater, &succeeded)
|
||||
txerr := sqlutil.EndTransaction(updater, &succeeded)
|
||||
if err == nil && txerr != nil {
|
||||
err = txerr
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/roomserver/state"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -60,7 +60,7 @@ func (r *RoomserverInternalAPI) updateLatestEvents(
|
|||
}
|
||||
succeeded := false
|
||||
defer func() {
|
||||
txerr := internal.EndTransaction(updater, &succeeded)
|
||||
txerr := sqlutil.EndTransaction(updater, &succeeded)
|
||||
if err == nil && txerr != nil {
|
||||
err = txerr
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"time"
|
||||
|
||||
fsAPI "github.com/matrix-org/dendrite/federationsender/api"
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -159,7 +159,7 @@ func (r *RoomserverInternalAPI) performJoinRoomByID(
|
|||
// TODO: Check what happens if the room exists on the server
|
||||
// but everyone has since left. I suspect it does the wrong thing.
|
||||
buildRes := api.QueryLatestEventsAndStateResponse{}
|
||||
event, err := internal.BuildEvent(
|
||||
event, err := eventutil.BuildEvent(
|
||||
ctx, // the request context
|
||||
&eb, // the template join event
|
||||
r.Cfg, // the server configuration
|
||||
|
@ -202,7 +202,7 @@ func (r *RoomserverInternalAPI) performJoinRoomByID(
|
|||
}
|
||||
}
|
||||
|
||||
case internal.ErrRoomNoExists:
|
||||
case eventutil.ErrRoomNoExists:
|
||||
// The room doesn't exist. First of all check if the room is a local
|
||||
// room. If it is then there's nothing more to do - the room just
|
||||
// hasn't been created yet.
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"time"
|
||||
|
||||
fsAPI "github.com/matrix-org/dendrite/federationsender/api"
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
@ -97,7 +97,7 @@ func (r *RoomserverInternalAPI) performLeaveRoomByID(
|
|||
// TODO: Check what happens if the room exists on the server
|
||||
// but everyone has since left. I suspect it does the wrong thing.
|
||||
buildRes := api.QueryLatestEventsAndStateResponse{}
|
||||
event, err := internal.BuildEvent(
|
||||
event, err := eventutil.BuildEvent(
|
||||
ctx, // the request context
|
||||
&eb, // the template leave event
|
||||
r.Cfg, // the server configuration
|
||||
|
@ -106,7 +106,7 @@ func (r *RoomserverInternalAPI) performLeaveRoomByID(
|
|||
&buildRes, // the query response
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("internal.BuildEvent: %w", err)
|
||||
return fmt.Errorf("eventutil.BuildEvent: %w", err)
|
||||
}
|
||||
|
||||
// Give our leave event to the roomserver input stream. The
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
fsInputAPI "github.com/matrix-org/dendrite/federationsender/api"
|
||||
"github.com/matrix-org/dendrite/internal/caching"
|
||||
internalHTTP "github.com/matrix-org/dendrite/internal/http"
|
||||
"github.com/matrix-org/dendrite/internal/httputil"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
)
|
||||
|
@ -78,7 +78,7 @@ func (h *httpRoomserverInternalAPI) SetRoomAlias(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverSetRoomAliasPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// GetRoomIDForAlias implements RoomserverAliasAPI
|
||||
|
@ -91,7 +91,7 @@ func (h *httpRoomserverInternalAPI) GetRoomIDForAlias(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverGetRoomIDForAliasPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// GetAliasesForRoomID implements RoomserverAliasAPI
|
||||
|
@ -104,7 +104,7 @@ func (h *httpRoomserverInternalAPI) GetAliasesForRoomID(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverGetAliasesForRoomIDPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// GetCreatorIDForAlias implements RoomserverAliasAPI
|
||||
|
@ -117,7 +117,7 @@ func (h *httpRoomserverInternalAPI) GetCreatorIDForAlias(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverGetCreatorIDForAliasPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// RemoveRoomAlias implements RoomserverAliasAPI
|
||||
|
@ -130,7 +130,7 @@ func (h *httpRoomserverInternalAPI) RemoveRoomAlias(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverRemoveRoomAliasPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// InputRoomEvents implements RoomserverInputAPI
|
||||
|
@ -143,7 +143,7 @@ func (h *httpRoomserverInternalAPI) InputRoomEvents(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverInputRoomEventsPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
func (h *httpRoomserverInternalAPI) PerformJoin(
|
||||
|
@ -155,7 +155,7 @@ func (h *httpRoomserverInternalAPI) PerformJoin(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverPerformJoinPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
func (h *httpRoomserverInternalAPI) PerformLeave(
|
||||
|
@ -167,7 +167,7 @@ func (h *httpRoomserverInternalAPI) PerformLeave(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverPerformLeavePath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// QueryLatestEventsAndState implements RoomserverQueryAPI
|
||||
|
@ -180,7 +180,7 @@ func (h *httpRoomserverInternalAPI) QueryLatestEventsAndState(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverQueryLatestEventsAndStatePath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// QueryStateAfterEvents implements RoomserverQueryAPI
|
||||
|
@ -193,7 +193,7 @@ func (h *httpRoomserverInternalAPI) QueryStateAfterEvents(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverQueryStateAfterEventsPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// QueryEventsByID implements RoomserverQueryAPI
|
||||
|
@ -206,7 +206,7 @@ func (h *httpRoomserverInternalAPI) QueryEventsByID(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverQueryEventsByIDPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// QueryMembershipForUser implements RoomserverQueryAPI
|
||||
|
@ -219,7 +219,7 @@ func (h *httpRoomserverInternalAPI) QueryMembershipForUser(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverQueryMembershipForUserPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// QueryMembershipsForRoom implements RoomserverQueryAPI
|
||||
|
@ -232,7 +232,7 @@ func (h *httpRoomserverInternalAPI) QueryMembershipsForRoom(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverQueryMembershipsForRoomPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// QueryServerAllowedToSeeEvent implements RoomserverQueryAPI
|
||||
|
@ -245,7 +245,7 @@ func (h *httpRoomserverInternalAPI) QueryServerAllowedToSeeEvent(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverQueryServerAllowedToSeeEventPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// QueryMissingEvents implements RoomServerQueryAPI
|
||||
|
@ -258,7 +258,7 @@ func (h *httpRoomserverInternalAPI) QueryMissingEvents(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverQueryMissingEventsPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// QueryStateAndAuthChain implements RoomserverQueryAPI
|
||||
|
@ -271,7 +271,7 @@ func (h *httpRoomserverInternalAPI) QueryStateAndAuthChain(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverQueryStateAndAuthChainPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// PerformBackfill implements RoomServerQueryAPI
|
||||
|
@ -284,7 +284,7 @@ func (h *httpRoomserverInternalAPI) PerformBackfill(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverPerformBackfillPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// QueryRoomVersionCapabilities implements RoomServerQueryAPI
|
||||
|
@ -297,7 +297,7 @@ func (h *httpRoomserverInternalAPI) QueryRoomVersionCapabilities(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverQueryRoomVersionCapabilitiesPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// QueryRoomVersionForRoom implements RoomServerQueryAPI
|
||||
|
@ -315,7 +315,7 @@ func (h *httpRoomserverInternalAPI) QueryRoomVersionForRoom(
|
|||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + RoomserverQueryRoomVersionForRoomPath
|
||||
err := internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
if err == nil {
|
||||
h.cache.StoreRoomVersion(request.RoomID, response.RoomVersion)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/httputil"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
@ -14,7 +14,7 @@ import (
|
|||
// nolint: gocyclo
|
||||
func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
||||
internalAPIMux.Handle(RoomserverInputRoomEventsPath,
|
||||
internal.MakeInternalAPI("inputRoomEvents", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("inputRoomEvents", func(req *http.Request) util.JSONResponse {
|
||||
var request api.InputRoomEventsRequest
|
||||
var response api.InputRoomEventsResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -27,7 +27,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
}),
|
||||
)
|
||||
internalAPIMux.Handle(RoomserverPerformJoinPath,
|
||||
internal.MakeInternalAPI("performJoin", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("performJoin", func(req *http.Request) util.JSONResponse {
|
||||
var request api.PerformJoinRequest
|
||||
var response api.PerformJoinResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -40,7 +40,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
}),
|
||||
)
|
||||
internalAPIMux.Handle(RoomserverPerformLeavePath,
|
||||
internal.MakeInternalAPI("performLeave", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("performLeave", func(req *http.Request) util.JSONResponse {
|
||||
var request api.PerformLeaveRequest
|
||||
var response api.PerformLeaveResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -54,7 +54,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverQueryLatestEventsAndStatePath,
|
||||
internal.MakeInternalAPI("queryLatestEventsAndState", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("queryLatestEventsAndState", func(req *http.Request) util.JSONResponse {
|
||||
var request api.QueryLatestEventsAndStateRequest
|
||||
var response api.QueryLatestEventsAndStateResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -68,7 +68,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverQueryStateAfterEventsPath,
|
||||
internal.MakeInternalAPI("queryStateAfterEvents", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("queryStateAfterEvents", func(req *http.Request) util.JSONResponse {
|
||||
var request api.QueryStateAfterEventsRequest
|
||||
var response api.QueryStateAfterEventsResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -82,7 +82,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverQueryEventsByIDPath,
|
||||
internal.MakeInternalAPI("queryEventsByID", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("queryEventsByID", func(req *http.Request) util.JSONResponse {
|
||||
var request api.QueryEventsByIDRequest
|
||||
var response api.QueryEventsByIDResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -96,7 +96,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverQueryMembershipForUserPath,
|
||||
internal.MakeInternalAPI("QueryMembershipForUser", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("QueryMembershipForUser", func(req *http.Request) util.JSONResponse {
|
||||
var request api.QueryMembershipForUserRequest
|
||||
var response api.QueryMembershipForUserResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -110,7 +110,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverQueryMembershipsForRoomPath,
|
||||
internal.MakeInternalAPI("queryMembershipsForRoom", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("queryMembershipsForRoom", func(req *http.Request) util.JSONResponse {
|
||||
var request api.QueryMembershipsForRoomRequest
|
||||
var response api.QueryMembershipsForRoomResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -124,7 +124,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverQueryServerAllowedToSeeEventPath,
|
||||
internal.MakeInternalAPI("queryServerAllowedToSeeEvent", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("queryServerAllowedToSeeEvent", func(req *http.Request) util.JSONResponse {
|
||||
var request api.QueryServerAllowedToSeeEventRequest
|
||||
var response api.QueryServerAllowedToSeeEventResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -138,7 +138,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverQueryMissingEventsPath,
|
||||
internal.MakeInternalAPI("queryMissingEvents", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("queryMissingEvents", func(req *http.Request) util.JSONResponse {
|
||||
var request api.QueryMissingEventsRequest
|
||||
var response api.QueryMissingEventsResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -152,7 +152,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverQueryStateAndAuthChainPath,
|
||||
internal.MakeInternalAPI("queryStateAndAuthChain", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("queryStateAndAuthChain", func(req *http.Request) util.JSONResponse {
|
||||
var request api.QueryStateAndAuthChainRequest
|
||||
var response api.QueryStateAndAuthChainResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -166,7 +166,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverPerformBackfillPath,
|
||||
internal.MakeInternalAPI("PerformBackfill", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("PerformBackfill", func(req *http.Request) util.JSONResponse {
|
||||
var request api.PerformBackfillRequest
|
||||
var response api.PerformBackfillResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -180,7 +180,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverQueryRoomVersionCapabilitiesPath,
|
||||
internal.MakeInternalAPI("QueryRoomVersionCapabilities", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("QueryRoomVersionCapabilities", func(req *http.Request) util.JSONResponse {
|
||||
var request api.QueryRoomVersionCapabilitiesRequest
|
||||
var response api.QueryRoomVersionCapabilitiesResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -194,7 +194,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverQueryRoomVersionForRoomPath,
|
||||
internal.MakeInternalAPI("QueryRoomVersionForRoom", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("QueryRoomVersionForRoom", func(req *http.Request) util.JSONResponse {
|
||||
var request api.QueryRoomVersionForRoomRequest
|
||||
var response api.QueryRoomVersionForRoomResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -208,7 +208,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverSetRoomAliasPath,
|
||||
internal.MakeInternalAPI("setRoomAlias", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("setRoomAlias", func(req *http.Request) util.JSONResponse {
|
||||
var request api.SetRoomAliasRequest
|
||||
var response api.SetRoomAliasResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -222,7 +222,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverGetRoomIDForAliasPath,
|
||||
internal.MakeInternalAPI("GetRoomIDForAlias", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("GetRoomIDForAlias", func(req *http.Request) util.JSONResponse {
|
||||
var request api.GetRoomIDForAliasRequest
|
||||
var response api.GetRoomIDForAliasResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -236,7 +236,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverGetCreatorIDForAliasPath,
|
||||
internal.MakeInternalAPI("GetCreatorIDForAlias", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("GetCreatorIDForAlias", func(req *http.Request) util.JSONResponse {
|
||||
var request api.GetCreatorIDForAliasRequest
|
||||
var response api.GetCreatorIDForAliasResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -250,7 +250,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverGetAliasesForRoomIDPath,
|
||||
internal.MakeInternalAPI("getAliasesForRoomID", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("getAliasesForRoomID", func(req *http.Request) util.JSONResponse {
|
||||
var request api.GetAliasesForRoomIDRequest
|
||||
var response api.GetAliasesForRoomIDResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
@ -264,7 +264,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverRemoveRoomAliasPath,
|
||||
internal.MakeInternalAPI("removeRoomAlias", func(req *http.Request) util.JSONResponse {
|
||||
httputil.MakeInternalAPI("removeRoomAlias", func(req *http.Request) util.JSONResponse {
|
||||
var request api.RemoveRoomAliasRequest
|
||||
var response api.RemoveRoomAliasResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
|
|
|
@ -20,7 +20,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/roomserver/inthttp"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/basecomponent"
|
||||
"github.com/matrix-org/dendrite/internal/setup"
|
||||
"github.com/matrix-org/dendrite/roomserver/internal"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -35,7 +35,7 @@ func AddInternalRoutes(router *mux.Router, intAPI api.RoomserverInternalAPI) {
|
|||
// NewInternalAPI returns a concerete implementation of the internal API. Callers
|
||||
// can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes.
|
||||
func NewInternalAPI(
|
||||
base *basecomponent.BaseDendrite,
|
||||
base *setup.BaseDendrite,
|
||||
keyRing gomatrixserverlib.JSONVerifier,
|
||||
fedClient *gomatrixserverlib.FederationClient,
|
||||
) api.RoomserverInternalAPI {
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"database/sql"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
"github.com/lib/pq"
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -94,7 +95,7 @@ func (s *eventStateKeyStatements) InsertEventStateKeyNID(
|
|||
ctx context.Context, txn *sql.Tx, eventStateKey string,
|
||||
) (types.EventStateKeyNID, error) {
|
||||
var eventStateKeyNID int64
|
||||
stmt := internal.TxStmt(txn, s.insertEventStateKeyNIDStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.insertEventStateKeyNIDStmt)
|
||||
err := stmt.QueryRowContext(ctx, eventStateKey).Scan(&eventStateKeyNID)
|
||||
return types.EventStateKeyNID(eventStateKeyNID), err
|
||||
}
|
||||
|
@ -103,7 +104,7 @@ func (s *eventStateKeyStatements) SelectEventStateKeyNID(
|
|||
ctx context.Context, txn *sql.Tx, eventStateKey string,
|
||||
) (types.EventStateKeyNID, error) {
|
||||
var eventStateKeyNID int64
|
||||
stmt := internal.TxStmt(txn, s.selectEventStateKeyNIDStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectEventStateKeyNIDStmt)
|
||||
err := stmt.QueryRowContext(ctx, eventStateKey).Scan(&eventStateKeyNID)
|
||||
return types.EventStateKeyNID(eventStateKeyNID), err
|
||||
}
|
||||
|
|
|
@ -19,9 +19,8 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
|
||||
"github.com/lib/pq"
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
|
||||
"github.com/lib/pq"
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -284,13 +285,13 @@ func (s *eventStatements) UpdateEventState(
|
|||
func (s *eventStatements) SelectEventSentToOutput(
|
||||
ctx context.Context, txn *sql.Tx, eventNID types.EventNID,
|
||||
) (sentToOutput bool, err error) {
|
||||
stmt := internal.TxStmt(txn, s.selectEventSentToOutputStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectEventSentToOutputStmt)
|
||||
err = stmt.QueryRowContext(ctx, int64(eventNID)).Scan(&sentToOutput)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *eventStatements) UpdateEventSentToOutput(ctx context.Context, txn *sql.Tx, eventNID types.EventNID) error {
|
||||
stmt := internal.TxStmt(txn, s.updateEventSentToOutputStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.updateEventSentToOutputStmt)
|
||||
_, err := stmt.ExecContext(ctx, int64(eventNID))
|
||||
return err
|
||||
}
|
||||
|
@ -298,7 +299,7 @@ func (s *eventStatements) UpdateEventSentToOutput(ctx context.Context, txn *sql.
|
|||
func (s *eventStatements) SelectEventID(
|
||||
ctx context.Context, txn *sql.Tx, eventNID types.EventNID,
|
||||
) (eventID string, err error) {
|
||||
stmt := internal.TxStmt(txn, s.selectEventIDStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectEventIDStmt)
|
||||
err = stmt.QueryRowContext(ctx, int64(eventNID)).Scan(&eventID)
|
||||
return
|
||||
}
|
||||
|
@ -306,7 +307,7 @@ func (s *eventStatements) SelectEventID(
|
|||
func (s *eventStatements) BulkSelectStateAtEventAndReference(
|
||||
ctx context.Context, txn *sql.Tx, eventNIDs []types.EventNID,
|
||||
) ([]types.StateAtEventAndReference, error) {
|
||||
stmt := internal.TxStmt(txn, s.bulkSelectStateAtEventAndReferenceStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.bulkSelectStateAtEventAndReferenceStmt)
|
||||
rows, err := stmt.QueryContext(ctx, eventNIDsAsArray(eventNIDs))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"database/sql"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -101,7 +102,7 @@ func (s *inviteStatements) InsertInviteEvent(
|
|||
targetUserNID, senderUserNID types.EventStateKeyNID,
|
||||
inviteEventJSON []byte,
|
||||
) (bool, error) {
|
||||
result, err := internal.TxStmt(txn, s.insertInviteEventStmt).ExecContext(
|
||||
result, err := sqlutil.TxStmt(txn, s.insertInviteEventStmt).ExecContext(
|
||||
ctx, inviteEventID, roomNID, targetUserNID, senderUserNID, inviteEventJSON,
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -118,7 +119,7 @@ func (s *inviteStatements) UpdateInviteRetired(
|
|||
ctx context.Context,
|
||||
txn *sql.Tx, roomNID types.RoomNID, targetUserNID types.EventStateKeyNID,
|
||||
) ([]string, error) {
|
||||
stmt := internal.TxStmt(txn, s.updateInviteRetiredStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.updateInviteRetiredStmt)
|
||||
rows, err := stmt.QueryContext(ctx, roomNID, targetUserNID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"database/sql"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -133,7 +134,7 @@ func (s *membershipStatements) InsertMembership(
|
|||
txn *sql.Tx, roomNID types.RoomNID, targetUserNID types.EventStateKeyNID,
|
||||
localTarget bool,
|
||||
) error {
|
||||
stmt := internal.TxStmt(txn, s.insertMembershipStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.insertMembershipStmt)
|
||||
_, err := stmt.ExecContext(ctx, roomNID, targetUserNID, localTarget)
|
||||
return err
|
||||
}
|
||||
|
@ -142,7 +143,7 @@ func (s *membershipStatements) SelectMembershipForUpdate(
|
|||
ctx context.Context,
|
||||
txn *sql.Tx, roomNID types.RoomNID, targetUserNID types.EventStateKeyNID,
|
||||
) (membership tables.MembershipState, err error) {
|
||||
err = internal.TxStmt(txn, s.selectMembershipForUpdateStmt).QueryRowContext(
|
||||
err = sqlutil.TxStmt(txn, s.selectMembershipForUpdateStmt).QueryRowContext(
|
||||
ctx, roomNID, targetUserNID,
|
||||
).Scan(&membership)
|
||||
return
|
||||
|
@ -216,7 +217,7 @@ func (s *membershipStatements) UpdateMembership(
|
|||
senderUserNID types.EventStateKeyNID, membership tables.MembershipState,
|
||||
eventNID types.EventNID,
|
||||
) error {
|
||||
_, err := internal.TxStmt(txn, s.updateMembershipStmt).ExecContext(
|
||||
_, err := sqlutil.TxStmt(txn, s.updateMembershipStmt).ExecContext(
|
||||
ctx, roomNID, targetUserNID, senderUserNID, membership, eventNID,
|
||||
)
|
||||
return err
|
||||
|
|
|
@ -19,7 +19,7 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -85,7 +85,7 @@ func (s *previousEventStatements) InsertPreviousEvent(
|
|||
previousEventReferenceSHA256 []byte,
|
||||
eventNID types.EventNID,
|
||||
) error {
|
||||
stmt := internal.TxStmt(txn, s.insertPreviousEventStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.insertPreviousEventStmt)
|
||||
_, err := stmt.ExecContext(
|
||||
ctx, previousEventID, previousEventReferenceSHA256, int64(eventNID),
|
||||
)
|
||||
|
@ -98,6 +98,6 @@ func (s *previousEventStatements) SelectPreviousEventExists(
|
|||
ctx context.Context, txn *sql.Tx, eventID string, eventReferenceSHA256 []byte,
|
||||
) error {
|
||||
var ok int64
|
||||
stmt := internal.TxStmt(txn, s.selectPreviousEventExistsStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectPreviousEventExistsStmt)
|
||||
return stmt.QueryRowContext(ctx, eventID, eventReferenceSHA256).Scan(&ok)
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
"errors"
|
||||
|
||||
"github.com/lib/pq"
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -106,7 +106,7 @@ func (s *roomStatements) InsertRoomNID(
|
|||
roomID string, roomVersion gomatrixserverlib.RoomVersion,
|
||||
) (types.RoomNID, error) {
|
||||
var roomNID int64
|
||||
stmt := internal.TxStmt(txn, s.insertRoomNIDStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.insertRoomNIDStmt)
|
||||
err := stmt.QueryRowContext(ctx, roomID, roomVersion).Scan(&roomNID)
|
||||
return types.RoomNID(roomNID), err
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ func (s *roomStatements) SelectRoomNID(
|
|||
ctx context.Context, txn *sql.Tx, roomID string,
|
||||
) (types.RoomNID, error) {
|
||||
var roomNID int64
|
||||
stmt := internal.TxStmt(txn, s.selectRoomNIDStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectRoomNIDStmt)
|
||||
err := stmt.QueryRowContext(ctx, roomID).Scan(&roomNID)
|
||||
return types.RoomNID(roomNID), err
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ func (s *roomStatements) SelectLatestEventsNIDsForUpdate(
|
|||
var nids pq.Int64Array
|
||||
var lastEventSentNID int64
|
||||
var stateSnapshotNID int64
|
||||
stmt := internal.TxStmt(txn, s.selectLatestEventNIDsForUpdateStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectLatestEventNIDsForUpdateStmt)
|
||||
err := stmt.QueryRowContext(ctx, int64(roomNID)).Scan(&nids, &lastEventSentNID, &stateSnapshotNID)
|
||||
if err != nil {
|
||||
return nil, 0, 0, err
|
||||
|
@ -163,7 +163,7 @@ func (s *roomStatements) UpdateLatestEventNIDs(
|
|||
lastEventSentNID types.EventNID,
|
||||
stateSnapshotNID types.StateSnapshotNID,
|
||||
) error {
|
||||
stmt := internal.TxStmt(txn, s.updateLatestEventNIDsStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.updateLatestEventNIDsStmt)
|
||||
_, err := stmt.ExecContext(
|
||||
ctx,
|
||||
roomNID,
|
||||
|
@ -178,7 +178,7 @@ func (s *roomStatements) SelectRoomVersionForRoomID(
|
|||
ctx context.Context, txn *sql.Tx, roomID string,
|
||||
) (gomatrixserverlib.RoomVersion, error) {
|
||||
var roomVersion gomatrixserverlib.RoomVersion
|
||||
stmt := internal.TxStmt(txn, s.selectRoomVersionForRoomIDStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectRoomVersionForRoomIDStmt)
|
||||
err := stmt.QueryRowContext(ctx, roomID).Scan(&roomVersion)
|
||||
if err == sql.ErrNoRows {
|
||||
return roomVersion, errors.New("room not found")
|
||||
|
|
|
@ -21,9 +21,8 @@ import (
|
|||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
|
||||
"github.com/lib/pq"
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
|
|
@ -18,7 +18,6 @@ package postgres
|
|||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
|
||||
// Import the postgres database driver.
|
||||
|
@ -33,7 +32,7 @@ type Database struct {
|
|||
|
||||
// Open a postgres database.
|
||||
// nolint: gocyclo
|
||||
func Open(dataSourceName string, dbProperties internal.DbProperties) (*Database, error) {
|
||||
func Open(dataSourceName string, dbProperties sqlutil.DbProperties) (*Database, error) {
|
||||
var d Database
|
||||
var db *sql.DB
|
||||
var err error
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"database/sql"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -68,7 +68,7 @@ func (d *Database) AddState(
|
|||
stateBlockNIDs []types.StateBlockNID,
|
||||
state []types.StateEntry,
|
||||
) (stateNID types.StateSnapshotNID, err error) {
|
||||
err = internal.WithTransaction(d.DB, func(txn *sql.Tx) error {
|
||||
err = sqlutil.WithTransaction(d.DB, func(txn *sql.Tx) error {
|
||||
if len(state) > 0 {
|
||||
var stateBlockNID types.StateBlockNID
|
||||
stateBlockNID, err = d.StateBlockTable.BulkInsertStateData(ctx, txn, state)
|
||||
|
@ -158,7 +158,7 @@ func (d *Database) RoomNIDExcludingStubs(ctx context.Context, roomID string) (ro
|
|||
func (d *Database) LatestEventIDs(
|
||||
ctx context.Context, roomNID types.RoomNID,
|
||||
) (references []gomatrixserverlib.EventReference, currentStateSnapshotNID types.StateSnapshotNID, depth int64, err error) {
|
||||
err = internal.WithTransaction(d.DB, func(txn *sql.Tx) error {
|
||||
err = sqlutil.WithTransaction(d.DB, func(txn *sql.Tx) error {
|
||||
var eventNIDs []types.EventNID
|
||||
eventNIDs, currentStateSnapshotNID, err = d.RoomsTable.SelectLatestEventNIDs(ctx, txn, roomNID)
|
||||
if err != nil {
|
||||
|
@ -337,7 +337,7 @@ func (d *Database) StoreEvent(
|
|||
err error
|
||||
)
|
||||
|
||||
err = internal.WithTransaction(d.DB, func(txn *sql.Tx) error {
|
||||
err = sqlutil.WithTransaction(d.DB, func(txn *sql.Tx) error {
|
||||
if txnAndSessionID != nil {
|
||||
if err = d.TransactionsTable.InsertTransaction(
|
||||
ctx, txn, txnAndSessionID.TransactionID,
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -69,7 +70,7 @@ func NewSqliteEventJSONTable(db *sql.DB) (tables.EventJSON, error) {
|
|||
func (s *eventJSONStatements) InsertEventJSON(
|
||||
ctx context.Context, txn *sql.Tx, eventNID types.EventNID, eventJSON []byte,
|
||||
) error {
|
||||
_, err := internal.TxStmt(txn, s.insertEventJSONStmt).ExecContext(ctx, int64(eventNID), eventJSON)
|
||||
_, err := sqlutil.TxStmt(txn, s.insertEventJSONStmt).ExecContext(ctx, int64(eventNID), eventJSON)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -80,7 +81,7 @@ func (s *eventJSONStatements) BulkSelectEventJSON(
|
|||
for k, v := range eventNIDs {
|
||||
iEventNIDs[k] = v
|
||||
}
|
||||
selectOrig := strings.Replace(bulkSelectEventJSONSQL, "($1)", internal.QueryVariadic(len(iEventNIDs)), 1)
|
||||
selectOrig := strings.Replace(bulkSelectEventJSONSQL, "($1)", sqlutil.QueryVariadic(len(iEventNIDs)), 1)
|
||||
|
||||
rows, err := s.db.QueryContext(ctx, selectOrig, iEventNIDs...)
|
||||
if err != nil {
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -90,7 +91,7 @@ func (s *eventStateKeyStatements) InsertEventStateKeyNID(
|
|||
var eventStateKeyNID int64
|
||||
var err error
|
||||
var res sql.Result
|
||||
insertStmt := internal.TxStmt(txn, s.insertEventStateKeyNIDStmt)
|
||||
insertStmt := sqlutil.TxStmt(txn, s.insertEventStateKeyNIDStmt)
|
||||
if res, err = insertStmt.ExecContext(ctx, eventStateKey); err == nil {
|
||||
eventStateKeyNID, err = res.LastInsertId()
|
||||
}
|
||||
|
@ -101,7 +102,7 @@ func (s *eventStateKeyStatements) SelectEventStateKeyNID(
|
|||
ctx context.Context, txn *sql.Tx, eventStateKey string,
|
||||
) (types.EventStateKeyNID, error) {
|
||||
var eventStateKeyNID int64
|
||||
stmt := internal.TxStmt(txn, s.selectEventStateKeyNIDStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectEventStateKeyNIDStmt)
|
||||
err := stmt.QueryRowContext(ctx, eventStateKey).Scan(&eventStateKeyNID)
|
||||
return types.EventStateKeyNID(eventStateKeyNID), err
|
||||
}
|
||||
|
@ -113,7 +114,7 @@ func (s *eventStateKeyStatements) BulkSelectEventStateKeyNID(
|
|||
for k, v := range eventStateKeys {
|
||||
iEventStateKeys[k] = v
|
||||
}
|
||||
selectOrig := strings.Replace(bulkSelectEventStateKeySQL, "($1)", internal.QueryVariadic(len(eventStateKeys)), 1)
|
||||
selectOrig := strings.Replace(bulkSelectEventStateKeySQL, "($1)", sqlutil.QueryVariadic(len(eventStateKeys)), 1)
|
||||
|
||||
rows, err := s.db.QueryContext(ctx, selectOrig, iEventStateKeys...)
|
||||
if err != nil {
|
||||
|
@ -139,7 +140,7 @@ func (s *eventStateKeyStatements) BulkSelectEventStateKey(
|
|||
for k, v := range eventStateKeyNIDs {
|
||||
iEventStateKeyNIDs[k] = v
|
||||
}
|
||||
selectOrig := strings.Replace(bulkSelectEventStateKeyNIDSQL, "($1)", internal.QueryVariadic(len(eventStateKeyNIDs)), 1)
|
||||
selectOrig := strings.Replace(bulkSelectEventStateKeyNIDSQL, "($1)", sqlutil.QueryVariadic(len(eventStateKeyNIDs)), 1)
|
||||
|
||||
rows, err := s.db.QueryContext(ctx, selectOrig, iEventStateKeyNIDs...)
|
||||
if err != nil {
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -104,8 +105,8 @@ func (s *eventTypeStatements) InsertEventTypeNID(
|
|||
) (types.EventTypeNID, error) {
|
||||
var eventTypeNID int64
|
||||
var err error
|
||||
insertStmt := internal.TxStmt(tx, s.insertEventTypeNIDStmt)
|
||||
resultStmt := internal.TxStmt(tx, s.insertEventTypeNIDResultStmt)
|
||||
insertStmt := sqlutil.TxStmt(tx, s.insertEventTypeNIDStmt)
|
||||
resultStmt := sqlutil.TxStmt(tx, s.insertEventTypeNIDResultStmt)
|
||||
if _, err = insertStmt.ExecContext(ctx, eventType); err == nil {
|
||||
err = resultStmt.QueryRowContext(ctx).Scan(&eventTypeNID)
|
||||
}
|
||||
|
@ -116,7 +117,7 @@ func (s *eventTypeStatements) SelectEventTypeNID(
|
|||
ctx context.Context, tx *sql.Tx, eventType string,
|
||||
) (types.EventTypeNID, error) {
|
||||
var eventTypeNID int64
|
||||
selectStmt := internal.TxStmt(tx, s.selectEventTypeNIDStmt)
|
||||
selectStmt := sqlutil.TxStmt(tx, s.selectEventTypeNIDStmt)
|
||||
err := selectStmt.QueryRowContext(ctx, eventType).Scan(&eventTypeNID)
|
||||
return types.EventTypeNID(eventTypeNID), err
|
||||
}
|
||||
|
@ -129,7 +130,7 @@ func (s *eventTypeStatements) BulkSelectEventTypeNID(
|
|||
for k, v := range eventTypes {
|
||||
iEventTypes[k] = v
|
||||
}
|
||||
selectOrig := strings.Replace(bulkSelectEventTypeNIDSQL, "($1)", internal.QueryVariadic(len(iEventTypes)), 1)
|
||||
selectOrig := strings.Replace(bulkSelectEventTypeNIDSQL, "($1)", sqlutil.QueryVariadic(len(iEventTypes)), 1)
|
||||
selectPrep, err := s.db.Prepare(selectOrig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -150,7 +151,7 @@ func (s *eventStatements) InsertEvent(
|
|||
depth int64,
|
||||
) (types.EventNID, types.StateSnapshotNID, error) {
|
||||
// attempt to insert: the last_row_id is the event NID
|
||||
insertStmt := internal.TxStmt(txn, s.insertEventStmt)
|
||||
insertStmt := sqlutil.TxStmt(txn, s.insertEventStmt)
|
||||
result, err := insertStmt.ExecContext(
|
||||
ctx, int64(roomNID), int64(eventTypeNID), int64(eventStateKeyNID),
|
||||
eventID, referenceSHA256, eventNIDsAsArray(authEventNIDs), depth,
|
||||
|
@ -171,7 +172,7 @@ func (s *eventStatements) SelectEvent(
|
|||
) (types.EventNID, types.StateSnapshotNID, error) {
|
||||
var eventNID int64
|
||||
var stateNID int64
|
||||
selectStmt := internal.TxStmt(txn, s.selectEventStmt)
|
||||
selectStmt := sqlutil.TxStmt(txn, s.selectEventStmt)
|
||||
err := selectStmt.QueryRowContext(ctx, eventID).Scan(&eventNID, &stateNID)
|
||||
return types.EventNID(eventNID), types.StateSnapshotNID(stateNID), err
|
||||
}
|
||||
|
@ -186,7 +187,7 @@ func (s *eventStatements) BulkSelectStateEventByID(
|
|||
for k, v := range eventIDs {
|
||||
iEventIDs[k] = v
|
||||
}
|
||||
selectOrig := strings.Replace(bulkSelectStateEventByIDSQL, "($1)", internal.QueryVariadic(len(iEventIDs)), 1)
|
||||
selectOrig := strings.Replace(bulkSelectStateEventByIDSQL, "($1)", sqlutil.QueryVariadic(len(iEventIDs)), 1)
|
||||
selectStmt, err := s.db.Prepare(selectOrig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -238,7 +239,7 @@ func (s *eventStatements) BulkSelectStateAtEventByID(
|
|||
for k, v := range eventIDs {
|
||||
iEventIDs[k] = v
|
||||
}
|
||||
selectOrig := strings.Replace(bulkSelectStateAtEventByIDSQL, "($1)", internal.QueryVariadic(len(iEventIDs)), 1)
|
||||
selectOrig := strings.Replace(bulkSelectStateAtEventByIDSQL, "($1)", sqlutil.QueryVariadic(len(iEventIDs)), 1)
|
||||
selectStmt, err := s.db.Prepare(selectOrig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -285,7 +286,7 @@ func (s *eventStatements) UpdateEventState(
|
|||
func (s *eventStatements) SelectEventSentToOutput(
|
||||
ctx context.Context, txn *sql.Tx, eventNID types.EventNID,
|
||||
) (sentToOutput bool, err error) {
|
||||
selectStmt := internal.TxStmt(txn, s.selectEventSentToOutputStmt)
|
||||
selectStmt := sqlutil.TxStmt(txn, s.selectEventSentToOutputStmt)
|
||||
err = selectStmt.QueryRowContext(ctx, int64(eventNID)).Scan(&sentToOutput)
|
||||
//err = s.selectEventSentToOutputStmt.QueryRowContext(ctx, int64(eventNID)).Scan(&sentToOutput)
|
||||
if err != nil {
|
||||
|
@ -294,7 +295,7 @@ func (s *eventStatements) SelectEventSentToOutput(
|
|||
}
|
||||
|
||||
func (s *eventStatements) UpdateEventSentToOutput(ctx context.Context, txn *sql.Tx, eventNID types.EventNID) error {
|
||||
updateStmt := internal.TxStmt(txn, s.updateEventSentToOutputStmt)
|
||||
updateStmt := sqlutil.TxStmt(txn, s.updateEventSentToOutputStmt)
|
||||
_, err := updateStmt.ExecContext(ctx, int64(eventNID))
|
||||
//_, err := s.updateEventSentToOutputStmt.ExecContext(ctx, int64(eventNID))
|
||||
return err
|
||||
|
@ -303,7 +304,7 @@ func (s *eventStatements) UpdateEventSentToOutput(ctx context.Context, txn *sql.
|
|||
func (s *eventStatements) SelectEventID(
|
||||
ctx context.Context, txn *sql.Tx, eventNID types.EventNID,
|
||||
) (eventID string, err error) {
|
||||
selectStmt := internal.TxStmt(txn, s.selectEventIDStmt)
|
||||
selectStmt := sqlutil.TxStmt(txn, s.selectEventIDStmt)
|
||||
err = selectStmt.QueryRowContext(ctx, int64(eventNID)).Scan(&eventID)
|
||||
return
|
||||
}
|
||||
|
@ -316,7 +317,7 @@ func (s *eventStatements) BulkSelectStateAtEventAndReference(
|
|||
for k, v := range eventNIDs {
|
||||
iEventNIDs[k] = v
|
||||
}
|
||||
selectOrig := strings.Replace(bulkSelectStateAtEventAndReferenceSQL, "($1)", internal.QueryVariadic(len(iEventNIDs)), 1)
|
||||
selectOrig := strings.Replace(bulkSelectStateAtEventAndReferenceSQL, "($1)", sqlutil.QueryVariadic(len(iEventNIDs)), 1)
|
||||
//////////////
|
||||
|
||||
rows, err := txn.QueryContext(ctx, selectOrig, iEventNIDs...)
|
||||
|
@ -362,14 +363,14 @@ func (s *eventStatements) BulkSelectEventReference(
|
|||
for k, v := range eventNIDs {
|
||||
iEventNIDs[k] = v
|
||||
}
|
||||
selectOrig := strings.Replace(bulkSelectEventReferenceSQL, "($1)", internal.QueryVariadic(len(iEventNIDs)), 1)
|
||||
selectOrig := strings.Replace(bulkSelectEventReferenceSQL, "($1)", sqlutil.QueryVariadic(len(iEventNIDs)), 1)
|
||||
selectPrep, err := txn.Prepare(selectOrig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
///////////////
|
||||
|
||||
selectStmt := internal.TxStmt(txn, selectPrep)
|
||||
selectStmt := sqlutil.TxStmt(txn, selectPrep)
|
||||
rows, err := selectStmt.QueryContext(ctx, iEventNIDs...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -396,7 +397,7 @@ func (s *eventStatements) BulkSelectEventID(ctx context.Context, eventNIDs []typ
|
|||
for k, v := range eventNIDs {
|
||||
iEventNIDs[k] = v
|
||||
}
|
||||
selectOrig := strings.Replace(bulkSelectEventIDSQL, "($1)", internal.QueryVariadic(len(iEventNIDs)), 1)
|
||||
selectOrig := strings.Replace(bulkSelectEventIDSQL, "($1)", sqlutil.QueryVariadic(len(iEventNIDs)), 1)
|
||||
selectStmt, err := s.db.Prepare(selectOrig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -432,7 +433,7 @@ func (s *eventStatements) BulkSelectEventNID(ctx context.Context, eventIDs []str
|
|||
for k, v := range eventIDs {
|
||||
iEventIDs[k] = v
|
||||
}
|
||||
selectOrig := strings.Replace(bulkSelectEventNIDSQL, "($1)", internal.QueryVariadic(len(iEventIDs)), 1)
|
||||
selectOrig := strings.Replace(bulkSelectEventNIDSQL, "($1)", sqlutil.QueryVariadic(len(iEventIDs)), 1)
|
||||
selectStmt, err := s.db.Prepare(selectOrig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -461,7 +462,7 @@ func (s *eventStatements) SelectMaxEventDepth(ctx context.Context, txn *sql.Tx,
|
|||
for i, v := range eventNIDs {
|
||||
iEventIDs[i] = v
|
||||
}
|
||||
sqlStr := strings.Replace(selectMaxEventDepthSQL, "($1)", internal.QueryVariadic(len(iEventIDs)), 1)
|
||||
sqlStr := strings.Replace(selectMaxEventDepthSQL, "($1)", sqlutil.QueryVariadic(len(iEventIDs)), 1)
|
||||
err := txn.QueryRowContext(ctx, sqlStr, iEventIDs...).Scan(&result)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"database/sql"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -89,7 +90,7 @@ func (s *inviteStatements) InsertInviteEvent(
|
|||
targetUserNID, senderUserNID types.EventStateKeyNID,
|
||||
inviteEventJSON []byte,
|
||||
) (bool, error) {
|
||||
stmt := internal.TxStmt(txn, s.insertInviteEventStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.insertInviteEventStmt)
|
||||
result, err := stmt.ExecContext(
|
||||
ctx, inviteEventID, roomNID, targetUserNID, senderUserNID, inviteEventJSON,
|
||||
)
|
||||
|
@ -108,7 +109,7 @@ func (s *inviteStatements) UpdateInviteRetired(
|
|||
txn *sql.Tx, roomNID types.RoomNID, targetUserNID types.EventStateKeyNID,
|
||||
) (eventIDs []string, err error) {
|
||||
// gather all the event IDs we will retire
|
||||
stmt := internal.TxStmt(txn, s.selectInvitesAboutToRetireStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectInvitesAboutToRetireStmt)
|
||||
rows, err := stmt.QueryContext(ctx, roomNID, targetUserNID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -123,7 +124,7 @@ func (s *inviteStatements) UpdateInviteRetired(
|
|||
}
|
||||
|
||||
// now retire the invites
|
||||
stmt = internal.TxStmt(txn, s.updateInviteRetiredStmt)
|
||||
stmt = sqlutil.TxStmt(txn, s.updateInviteRetiredStmt)
|
||||
_, err = stmt.ExecContext(ctx, roomNID, targetUserNID)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"database/sql"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -109,7 +110,7 @@ func (s *membershipStatements) InsertMembership(
|
|||
roomNID types.RoomNID, targetUserNID types.EventStateKeyNID,
|
||||
localTarget bool,
|
||||
) error {
|
||||
stmt := internal.TxStmt(txn, s.insertMembershipStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.insertMembershipStmt)
|
||||
_, err := stmt.ExecContext(ctx, roomNID, targetUserNID, localTarget)
|
||||
return err
|
||||
}
|
||||
|
@ -118,7 +119,7 @@ func (s *membershipStatements) SelectMembershipForUpdate(
|
|||
ctx context.Context, txn *sql.Tx,
|
||||
roomNID types.RoomNID, targetUserNID types.EventStateKeyNID,
|
||||
) (membership tables.MembershipState, err error) {
|
||||
stmt := internal.TxStmt(txn, s.selectMembershipForUpdateStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectMembershipForUpdateStmt)
|
||||
err = stmt.QueryRowContext(
|
||||
ctx, roomNID, targetUserNID,
|
||||
).Scan(&membership)
|
||||
|
@ -193,7 +194,7 @@ func (s *membershipStatements) UpdateMembership(
|
|||
senderUserNID types.EventStateKeyNID, membership tables.MembershipState,
|
||||
eventNID types.EventNID,
|
||||
) error {
|
||||
stmt := internal.TxStmt(txn, s.updateMembershipStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.updateMembershipStmt)
|
||||
_, err := stmt.ExecContext(
|
||||
ctx, senderUserNID, membership, eventNID, roomNID, targetUserNID,
|
||||
)
|
||||
|
|
|
@ -19,7 +19,7 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -77,7 +77,7 @@ func (s *previousEventStatements) InsertPreviousEvent(
|
|||
previousEventReferenceSHA256 []byte,
|
||||
eventNID types.EventNID,
|
||||
) error {
|
||||
stmt := internal.TxStmt(txn, s.insertPreviousEventStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.insertPreviousEventStmt)
|
||||
_, err := stmt.ExecContext(
|
||||
ctx, previousEventID, previousEventReferenceSHA256, int64(eventNID),
|
||||
)
|
||||
|
@ -90,6 +90,6 @@ func (s *previousEventStatements) SelectPreviousEventExists(
|
|||
ctx context.Context, txn *sql.Tx, eventID string, eventReferenceSHA256 []byte,
|
||||
) error {
|
||||
var ok int64
|
||||
stmt := internal.TxStmt(txn, s.selectPreviousEventExistsStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectPreviousEventExistsStmt)
|
||||
return stmt.QueryRowContext(ctx, eventID, eventReferenceSHA256).Scan(&ok)
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -95,7 +95,7 @@ func (s *roomStatements) InsertRoomNID(
|
|||
roomID string, roomVersion gomatrixserverlib.RoomVersion,
|
||||
) (types.RoomNID, error) {
|
||||
var err error
|
||||
insertStmt := internal.TxStmt(txn, s.insertRoomNIDStmt)
|
||||
insertStmt := sqlutil.TxStmt(txn, s.insertRoomNIDStmt)
|
||||
if _, err = insertStmt.ExecContext(ctx, roomID, roomVersion); err == nil {
|
||||
return s.SelectRoomNID(ctx, txn, roomID)
|
||||
} else {
|
||||
|
@ -107,7 +107,7 @@ func (s *roomStatements) SelectRoomNID(
|
|||
ctx context.Context, txn *sql.Tx, roomID string,
|
||||
) (types.RoomNID, error) {
|
||||
var roomNID int64
|
||||
stmt := internal.TxStmt(txn, s.selectRoomNIDStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectRoomNIDStmt)
|
||||
err := stmt.QueryRowContext(ctx, roomID).Scan(&roomNID)
|
||||
return types.RoomNID(roomNID), err
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ func (s *roomStatements) SelectLatestEventNIDs(
|
|||
var eventNIDs []types.EventNID
|
||||
var nidsJSON string
|
||||
var stateSnapshotNID int64
|
||||
stmt := internal.TxStmt(txn, s.selectLatestEventNIDsStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectLatestEventNIDsStmt)
|
||||
err := stmt.QueryRowContext(ctx, int64(roomNID)).Scan(&nidsJSON, &stateSnapshotNID)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
|
@ -136,7 +136,7 @@ func (s *roomStatements) SelectLatestEventsNIDsForUpdate(
|
|||
var nidsJSON string
|
||||
var lastEventSentNID int64
|
||||
var stateSnapshotNID int64
|
||||
stmt := internal.TxStmt(txn, s.selectLatestEventNIDsForUpdateStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectLatestEventNIDsForUpdateStmt)
|
||||
err := stmt.QueryRowContext(ctx, int64(roomNID)).Scan(&nidsJSON, &lastEventSentNID, &stateSnapshotNID)
|
||||
if err != nil {
|
||||
return nil, 0, 0, err
|
||||
|
@ -155,7 +155,7 @@ func (s *roomStatements) UpdateLatestEventNIDs(
|
|||
lastEventSentNID types.EventNID,
|
||||
stateSnapshotNID types.StateSnapshotNID,
|
||||
) error {
|
||||
stmt := internal.TxStmt(txn, s.updateLatestEventNIDsStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.updateLatestEventNIDsStmt)
|
||||
_, err := stmt.ExecContext(
|
||||
ctx,
|
||||
eventNIDsAsArray(eventNIDs),
|
||||
|
@ -170,7 +170,7 @@ func (s *roomStatements) SelectRoomVersionForRoomID(
|
|||
ctx context.Context, txn *sql.Tx, roomID string,
|
||||
) (gomatrixserverlib.RoomVersion, error) {
|
||||
var roomVersion gomatrixserverlib.RoomVersion
|
||||
stmt := internal.TxStmt(txn, s.selectRoomVersionForRoomIDStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectRoomVersionForRoomIDStmt)
|
||||
err := stmt.QueryRowContext(ctx, roomID).Scan(&roomVersion)
|
||||
if err == sql.ErrNoRows {
|
||||
return roomVersion, errors.New("room not found")
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -130,7 +131,7 @@ func (s *stateBlockStatements) BulkSelectStateBlockEntries(
|
|||
for k, v := range stateBlockNIDs {
|
||||
nids[k] = v
|
||||
}
|
||||
selectOrig := strings.Replace(bulkSelectStateBlockEntriesSQL, "($1)", internal.QueryVariadic(len(nids)), 1)
|
||||
selectOrig := strings.Replace(bulkSelectStateBlockEntriesSQL, "($1)", sqlutil.QueryVariadic(len(nids)), 1)
|
||||
selectStmt, err := s.db.Prepare(selectOrig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -186,9 +187,9 @@ func (s *stateBlockStatements) BulkSelectFilteredStateBlockEntries(
|
|||
sort.Sort(tuples)
|
||||
|
||||
eventTypeNIDArray, eventStateKeyNIDArray := tuples.typesAndStateKeysAsArrays()
|
||||
sqlStatement := strings.Replace(bulkSelectFilteredStateBlockEntriesSQL, "($1)", internal.QueryVariadic(len(stateBlockNIDs)), 1)
|
||||
sqlStatement = strings.Replace(sqlStatement, "($2)", internal.QueryVariadicOffset(len(eventTypeNIDArray), len(stateBlockNIDs)), 1)
|
||||
sqlStatement = strings.Replace(sqlStatement, "($3)", internal.QueryVariadicOffset(len(eventStateKeyNIDArray), len(stateBlockNIDs)+len(eventTypeNIDArray)), 1)
|
||||
sqlStatement := strings.Replace(bulkSelectFilteredStateBlockEntriesSQL, "($1)", sqlutil.QueryVariadic(len(stateBlockNIDs)), 1)
|
||||
sqlStatement = strings.Replace(sqlStatement, "($2)", sqlutil.QueryVariadicOffset(len(eventTypeNIDArray), len(stateBlockNIDs)), 1)
|
||||
sqlStatement = strings.Replace(sqlStatement, "($3)", sqlutil.QueryVariadicOffset(len(eventStateKeyNIDArray), len(stateBlockNIDs)+len(eventTypeNIDArray)), 1)
|
||||
|
||||
var params []interface{}
|
||||
for _, val := range stateBlockNIDs {
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -92,7 +93,7 @@ func (s *stateSnapshotStatements) BulkSelectStateBlockNIDs(
|
|||
for k, v := range stateNIDs {
|
||||
nids[k] = v
|
||||
}
|
||||
selectOrig := strings.Replace(bulkSelectStateBlockNIDsSQL, "($1)", internal.QueryVariadic(len(nids)), 1)
|
||||
selectOrig := strings.Replace(bulkSelectStateBlockNIDsSQL, "($1)", sqlutil.QueryVariadic(len(nids)), 1)
|
||||
selectStmt, err := s.db.Prepare(selectOrig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -20,8 +20,6 @@ import (
|
|||
"database/sql"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
|
@ -52,7 +50,7 @@ func Open(dataSourceName string) (*Database, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if d.db, err = sqlutil.Open(internal.SQLiteDriverName(), cs, nil); err != nil {
|
||||
if d.db, err = sqlutil.Open(sqlutil.SQLiteDriverName(), cs, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//d.db.Exec("PRAGMA journal_mode=WAL;")
|
||||
|
|
|
@ -19,7 +19,7 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
)
|
||||
|
@ -68,7 +68,7 @@ func (s *transactionStatements) InsertTransaction(
|
|||
userID string,
|
||||
eventID string,
|
||||
) (err error) {
|
||||
stmt := internal.TxStmt(txn, s.insertTransactionStmt)
|
||||
stmt := sqlutil.TxStmt(txn, s.insertTransactionStmt)
|
||||
_, err = stmt.ExecContext(
|
||||
ctx, transactionID, sessionID, userID, eventID,
|
||||
)
|
||||
|
|
|
@ -19,13 +19,13 @@ package storage
|
|||
import (
|
||||
"net/url"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/postgres"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/sqlite3"
|
||||
)
|
||||
|
||||
// Open opens a database connection.
|
||||
func Open(dataSourceName string, dbProperties internal.DbProperties) (Database, error) {
|
||||
func Open(dataSourceName string, dbProperties sqlutil.DbProperties) (Database, error) {
|
||||
uri, err := url.Parse(dataSourceName)
|
||||
if err != nil {
|
||||
return postgres.Open(dataSourceName, dbProperties)
|
||||
|
|
|
@ -18,14 +18,14 @@ import (
|
|||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/sqlite3"
|
||||
)
|
||||
|
||||
// NewPublicRoomsServerDatabase opens a database connection.
|
||||
func Open(
|
||||
dataSourceName string,
|
||||
dbProperties internal.DbProperties, // nolint:unparam
|
||||
dbProperties sqlutil.DbProperties, // nolint:unparam
|
||||
) (Database, error) {
|
||||
uri, err := url.Parse(dataSourceName)
|
||||
if err != nil {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
|
@ -174,7 +174,7 @@ type RoomRecentEventsUpdater interface {
|
|||
// It will share the same transaction as this updater.
|
||||
MembershipUpdater(targetUserNID EventStateKeyNID, isTargetLocalUser bool) (MembershipUpdater, error)
|
||||
// Implements Transaction so it can be committed or rolledback
|
||||
internal.Transaction
|
||||
sqlutil.Transaction
|
||||
}
|
||||
|
||||
// A MembershipUpdater is used to update the membership of a user in a room.
|
||||
|
@ -199,7 +199,7 @@ type MembershipUpdater interface {
|
|||
// Returns a list of invite event IDs that this state change retired.
|
||||
SetToLeave(senderUserID string, eventID string) (inviteEventIDs []string, err error)
|
||||
// Implements Transaction so it can be committed or rolledback.
|
||||
internal.Transaction
|
||||
sqlutil.Transaction
|
||||
}
|
||||
|
||||
// A MissingEventError is an error that happened because the roomserver was
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue