Skip to content

add support notification from database#17

Closed
andrewst wants to merge 3 commits intostablekernel:masterfrom
andrewst:add_notification
Closed

add support notification from database#17
andrewst wants to merge 3 commits intostablekernel:masterfrom
andrewst:add_notification

Conversation

@andrewst
Copy link
Contributor

No description provided.

@andrewst
Copy link
Contributor Author

I think bad test "Notification many channel", any ideas?

@codecov-io
Copy link

codecov-io commented Jun 29, 2017

Codecov Report

Merging #17 into master will decrease coverage by 0.08%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #17      +/-   ##
==========================================
- Coverage   90.28%   90.19%   -0.09%     
==========================================
  Files          11       11              
  Lines         947      969      +22     
==========================================
+ Hits          855      874      +19     
- Misses         92       95       +3
Impacted Files Coverage Δ
lib/src/connection_fsm.dart 81.98% <ø> (ø) ⬆️
lib/src/query.dart 96.29% <ø> (ø) ⬆️
lib/src/connection.dart 92.1% <100%> (-0.28%) ⬇️
lib/src/server_messages.dart 91.76% <100%> (+1.35%) ⬆️
lib/src/message_window.dart 100% <100%> (ø) ⬆️
lib/src/transaction_proxy.dart 82.6% <0%> (-4.35%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f09c4bf...94503d9. Read the comment docs.

@andrewst
Copy link
Contributor Author

May be better moving process NotificationResponse into PostgreSQLConnection._readData?
And add processing NoticeResponse as the NotificationResponse.

Copy link
Contributor

@itsjoeconway itsjoeconway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GREAT tests! Few minor things to move around in the implementation.

_connectionState.connection = this;
}

final StreamController<Notification> _notifications = new StreamController<Notification>.broadcast();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Close this resource in PostgreSQLConnection.close(); make sure the future returned by PostgreSQLConnection.close() doesn't complete until StreamController.close()'s future completes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix this

@@ -12,6 +12,17 @@ abstract class _PostgreSQLConnectionState {
}

_PostgreSQLConnectionState onMessage(ServerMessage message) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since notifications don't have quite the same lifecycle or need for the finite state machine, it'd be better to make this if (message is NotificationResponseMessage) check in connection._readData and avoid the FSM altogether. There is already logic in connection._readData to separate out ErrorResponseMessages, so it'll fit right in.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, since (and if I'm wrong correct me) if NotificationResponseMessages come out of band - i.e. a Query does not trigger them, they are sent to to the user without request - we should wrap their processing in a try-catch block and emit an error on the broadcast stream if something within that processing fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how better make this, please hint me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm not sure if it makes sense - ignore this one

void readBytes(Uint8List bytes) {
var view = new ByteData.view(bytes.buffer, bytes.offsetInBytes);
processId = view.getUint32(0);
channel = UTF8.decode(bytes.sublist(4, bytes.indexOf(0, 4)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid a copy (bytes.sublist) on this line and the next by using UTF8.decoder.startChunkedConversion and piping it bytes from the view.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bah, this is my fault - I think your earlier implementation was just fine. If there really is a need to optimize this, there are a few other places to do it too, and that can wait. Can you revert back to what you had here? And then making the processID public on the connection, I think we're all set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I revert this, and create new clean PR.

}

class Notification {
final int processId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize the trailing d, e.g. ID to stay consistent with the Connection._processID

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is it possible to have some way of having the connection know if the notification was triggered by that connection? Would allow listeners to say 'Oh, I sent this, I can ignore it' but would also allow listeners to structure their app so they can listen for their own notifications, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't find in documentation postgresql nothing this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that when a connection is made a process ID is assigned to it (this should be stored in Connection._processID). When NOTIFY is delivered, the process ID is included in the delivery to each subscriber that matches the process ID of the connection that triggered the NOTIFY. An interested subscriber may want to be able to filter out NOTIFYs that they themselves sent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be property PostgreSQLConnection._pricessID make public?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it can get switched to public

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.

3 participants